Class: Commons::Lang::Builder::ToSStyle

Inherits:
Object
  • Object
show all
Defined in:
lib/commons/lang/builder/to_s_style.rb

Defined Under Namespace

Classes: DefaultToSStyle, MultiLineToSStyle, NoFieldNameToSStyle, ShortPrefixToSStyle, SimpleToSStyle

Constant Summary collapse

DEFAULT_STYLE =
DefaultToSStyle.new
MULTI_LINE_STYLE =
MultiLineToSStyle.new
NO_FIELD_NAMES_STYLE =
NoFieldNameToSStyle.new
SHORT_PREFIX_STYLE =
ShortPrefixToSStyle.new
SIMPLE_STYLE =
SimpleToSStyle.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeToSStyle

Returns a new instance of ToSStyle.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/commons/lang/builder/to_s_style.rb', line 62

def initialize
  super()
  
  @registry = Hash.new
  
  # Whether to use the field names, the default is true.
  @use_field_names = true
  
  # Whether to use the class name, the default is true.
  @use_class_name = true
  
  # Whether to use short class names, the default is false.
  @use_short_className = false
  
  #  Whether to use the identity hash code, the default is true.
  @use_identity_hash_code = true
  
  # The content start '{'.
  @content_start = '{'
  
  # The content end '}'.
  @content_end = '}'
  
  # The field name value separator '='.
  @field_name_value_separator = '='
  
  # Whether the field separator should be added before any other fields.
  @field_separator_at_start = false
  
  # Whether the field separator should be added after any other fields.
  @field_separator_at_end = false
  
  # The field separator ','.
  @field_separator = ','
  
  # The array start '['.
  @array_start = '['
  
  # The array separator ','.
  @array_separator = ','
  
  # The detail for array content.
  @array_content_detail = true
  
  # The array end ']'.
  @array_end = ']'
  
  # The value to use when fullDetail is nil,
  # the default value is true.
  @default_full_detail = true
  
  # The nil text '<nil>'.
  @nil_text = '<nil>'
  
  # The summary size text start '<size'.
  @size_start_text = '<size='
  
  # The summary size text start '&gt;'.
  @size_end_text = '>'
  
  # The summary object text start '&lt;'.
  @summary_object_start_text = '<'
  
  # The summary object text start '&gt;'.
  @summary_object_end_text = '>'
end

Instance Attribute Details

#array_content_detail=(value) ⇒ Object

Sets the attribute array_content_detail

Parameters:

  • value

    the value to set the attribute array_content_detail to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def array_content_detail=(value)
  @array_content_detail = value
end

#array_end=(value) ⇒ Object

Sets the attribute array_end

Parameters:

  • value

    the value to set the attribute array_end to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def array_end=(value)
  @array_end = value
end

#array_separator=(value) ⇒ Object

Sets the attribute array_separator

Parameters:

  • value

    the value to set the attribute array_separator to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def array_separator=(value)
  @array_separator = value
end

#array_start=(value) ⇒ Object

Sets the attribute array_start

Parameters:

  • value

    the value to set the attribute array_start to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def array_start=(value)
  @array_start = value
end

#content_end=(value) ⇒ Object

Sets the attribute content_end

Parameters:

  • value

    the value to set the attribute content_end to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def content_end=(value)
  @content_end = value
end

#content_start=(value) ⇒ Object

Sets the attribute content_start

Parameters:

  • value

    the value to set the attribute content_start to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def content_start=(value)
  @content_start = value
end

#default_full_detail=(value) ⇒ Object

Sets the attribute default_full_detail

Parameters:

  • value

    the value to set the attribute default_full_detail to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def default_full_detail=(value)
  @default_full_detail = value
end

#field_name_value_separator=(value) ⇒ Object

Sets the attribute field_name_value_separator

Parameters:

  • value

    the value to set the attribute field_name_value_separator to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def field_name_value_separator=(value)
  @field_name_value_separator = value
end

#field_separator=(value) ⇒ Object

Sets the attribute field_separator

Parameters:

  • value

    the value to set the attribute field_separator to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def field_separator=(value)
  @field_separator = value
end

#field_separator_at_end=(value) ⇒ Object

Sets the attribute field_separator_at_end

Parameters:

  • value

    the value to set the attribute field_separator_at_end to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def field_separator_at_end=(value)
  @field_separator_at_end = value
end

#field_separator_at_start=(value) ⇒ Object

Sets the attribute field_separator_at_start

Parameters:

  • value

    the value to set the attribute field_separator_at_start to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def field_separator_at_start=(value)
  @field_separator_at_start = value
end

#nil_text=(value) ⇒ Object

Sets the attribute nil_text

Parameters:

  • value

    the value to set the attribute nil_text to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def nil_text=(value)
  @nil_text = value
end

#size_end_text=(value) ⇒ Object

Sets the attribute size_end_text

Parameters:

  • value

    the value to set the attribute size_end_text to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def size_end_text=(value)
  @size_end_text = value
end

#size_start_text=(value) ⇒ Object

Sets the attribute size_start_text

Parameters:

  • value

    the value to set the attribute size_start_text to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def size_start_text=(value)
  @size_start_text = value
end

#summary_object_end_text=(value) ⇒ Object

Sets the attribute summary_object_end_text

Parameters:

  • value

    the value to set the attribute summary_object_end_text to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def summary_object_end_text=(value)
  @summary_object_end_text = value
end

#summary_object_start_text=(value) ⇒ Object

Sets the attribute summary_object_start_text

Parameters:

  • value

    the value to set the attribute summary_object_start_text to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def summary_object_start_text=(value)
  @summary_object_start_text = value
end

#use_class_name=(value) ⇒ Object

Sets the attribute use_class_name

Parameters:

  • value

    the value to set the attribute use_class_name to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def use_class_name=(value)
  @use_class_name = value
end

#use_field_names=(value) ⇒ Object

Sets the attribute use_field_names

Parameters:

  • value

    the value to set the attribute use_field_names to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def use_field_names=(value)
  @use_field_names = value
end

#use_identity_hash_code=(value) ⇒ Object

Sets the attribute use_identity_hash_code

Parameters:

  • value

    the value to set the attribute use_identity_hash_code to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def use_identity_hash_code=(value)
  @use_identity_hash_code = value
end

#use_short_className=(value) ⇒ Object

Sets the attribute use_short_className

Parameters:

  • value

    the value to set the attribute use_short_className to.



43
44
45
# File 'lib/commons/lang/builder/to_s_style.rb', line 43

def use_short_className=(value)
  @use_short_className = value
end

Instance Method Details

#append(buffer, field_name, value, full_detail) ⇒ Object

– —————————————————————————— ++



209
210
211
212
213
214
215
216
217
218
219
# File 'lib/commons/lang/builder/to_s_style.rb', line 209

def append(buffer, field_name, value, full_detail)
  append_field_start(buffer, field_name)
  
  if value == nil
    append_nil_text(buffer, field_name)
  else
    append_internal(buffer, field_name, value, full_detail)
  end
  
  append_field_end(buffer, field_name)
end

#append_end(buffer, object) ⇒ Object



180
181
182
183
184
185
# File 'lib/commons/lang/builder/to_s_style.rb', line 180

def append_end(buffer, object)
  if @field_separator_at_end == false
    remove_last_field_separator(buffer)
  end
  append_content_end(buffer)
end

#append_start(buffer, object) ⇒ Object



168
169
170
171
172
173
174
175
176
177
# File 'lib/commons/lang/builder/to_s_style.rb', line 168

def append_start(buffer, object)
  if object != nil
    append_class_name(buffer, object)
    append_identity_hash_code(buffer, object)
    append_content_start(buffer)
    if @field_separator_at_start
      append_field_separator(buffer)
    end
  end
end

#append_super(buffer, super_to_s) ⇒ Object



147
148
149
# File 'lib/commons/lang/builder/to_s_style.rb', line 147

def append_super(buffer, super_to_s)
  append_to_s(buffer, super_to_s)
end

#append_to_s(buffer, to_s) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/commons/lang/builder/to_s_style.rb', line 152

def append_to_s(buffer, to_s)
  if to_s != nil
    pos1 = to_s.index(@content_start) + @content_start.length
    pos2 = to_s.rindex(@content_end)
    if pos1 != pos2 && pos1 >= 0 && pos2 >= 0
      data = to_s[pos1 ... pos2]
      if @field_separator_at_start
        remove_last_field_separator(buffer)
      end
      buffer.concat(data)
      append_field_separator(buffer)
    end
  end
end

#register(value) ⇒ Object



135
136
137
138
139
# File 'lib/commons/lang/builder/to_s_style.rb', line 135

def register(value)
  if value != nil
    @registry[value.__id__] = value
  end
end

#registered?(value) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/commons/lang/builder/to_s_style.rb', line 130

def registered?(value)
  return @registry.has_key?(value.__id__)
end

#unregister(value) ⇒ Object



142
143
144
# File 'lib/commons/lang/builder/to_s_style.rb', line 142

def unregister(value)
  @registry.delete(value.__id__);
end