Class: TXTextControl::ReportingCloud::MergeField

Inherits:
Object
  • Object
show all
Defined in:
lib/txtextcontrol/reportingcloud/merge_field.rb

Overview

Represents a merge field in a document template.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date_time_format, name, numeric_format, preserve_formatting, text, text_after, text_before) ⇒ MergeField

Returns a new instance of MergeField

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/txtextcontrol/reportingcloud/merge_field.rb', line 37

def initialize(date_time_format, name, numeric_format, preserve_formatting, text, text_after, text_before)
  # Parameter validation
  unless date_time_format.nil? || (date_time_format.kind_of? String)
    raise ArgumentError, "Date / time format must be a string."
  end
  raise ArgumentError, "Field name must be a string." if !name.kind_of? String
  unless numeric_format.nil? || (numeric_format.kind_of? String)
    raise ArgumentError, "Numeric format must be a string"
  end
  raise ArgumentError, "Preserve formatting parameter must be a boolean value." if !!preserve_formatting != preserve_formatting
  raise ArgumentError, "Field text must be a string." if !text.kind_of? String
  raise ArgumentError, "Text after must be a string." if !text_after.nil? && (!text_after.kind_of? String)
  raise ArgumentError, "Text before must be a string." if !text_before.nil? && (!text_before.kind_of? String)

  @date_time_format = date_time_format
  @name = name
  @numeric_format = numeric_format
  @preserve_formatting = preserve_formatting
  @text = text
  @text_after = text_after
  @text_before = text_before
end

Instance Attribute Details

#date_time_formatString (readonly)

The format which is applied to date / time values.

Returns:

  • (String)

    the current value of date_time_format



28
29
30
# File 'lib/txtextcontrol/reportingcloud/merge_field.rb', line 28

def date_time_format
  @date_time_format
end

#nameString (readonly)

The name of the field.

Returns:

  • (String)

    the current value of name



28
29
30
# File 'lib/txtextcontrol/reportingcloud/merge_field.rb', line 28

def name
  @name
end

#numeric_formatString (readonly)

The format which is applied to numeric values.

Returns:

  • (String)

    the current value of numeric_format



28
29
30
# File 'lib/txtextcontrol/reportingcloud/merge_field.rb', line 28

def numeric_format
  @numeric_format
end

#preserve_formattingBoolean (readonly)

Specifies whether formatting is preserved.

Returns:

  • (Boolean)

    the current value of preserve_formatting



28
29
30
# File 'lib/txtextcontrol/reportingcloud/merge_field.rb', line 28

def preserve_formatting
  @preserve_formatting
end

#textString (readonly)

The field text.

Returns:

  • (String)

    the current value of text



28
29
30
# File 'lib/txtextcontrol/reportingcloud/merge_field.rb', line 28

def text
  @text
end

#text_afterString (readonly)

The text after the field.

Returns:

  • (String)

    the current value of text_after



28
29
30
# File 'lib/txtextcontrol/reportingcloud/merge_field.rb', line 28

def text_after
  @text_after
end

#text_beforeString (readonly)

The text before the field.

Returns:

  • (String)

    the current value of text_before



28
29
30
# File 'lib/txtextcontrol/reportingcloud/merge_field.rb', line 28

def text_before
  @text_before
end

Class Method Details

.from_camelized_hash(hash) ⇒ MergeField

Creates an MergeField instance from a hash.

Parameters:

  • hash (Hash)

    The hash to try and create an MergeField instance from.

Returns:

  • (MergeField)

    A newly created MergeField instance.

Raises:

  • (ArgumentError)


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/txtextcontrol/reportingcloud/merge_field.rb', line 63

def self.from_camelized_hash(hash) 
  # Parameter validation
  raise ArgumentError, "Parameter must be a Hash." if !hash.kind_of? Hash

  date_time_format = hash["dateTimeFormat"]
  name = hash["name"]
  numeric_format = hash["numericFormat"]
  preserve_formatting = hash["preserveFormatting"]
  text = hash["text"]
  text_after = hash["textAfter"]
  text_before = hash["textBefore"]
  return MergeField.new(date_time_format, name, numeric_format, preserve_formatting, text, text_after, text_before)
end