Class: Commons::Lang::Builder::ToSBuilder
- Inherits:
-
Object
- Object
- Commons::Lang::Builder::ToSBuilder
- Defined in:
- lib/commons/lang/builder/to_s_builder.rb
Overview
Constant Summary collapse
- @@default_style =
ToSStyle::DEFAULT_STYLE
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Class Method Summary collapse
Instance Method Summary collapse
- #append(field_name, value, full_detail = true) ⇒ Object
- #append_super(super_to_s) ⇒ Object
- #append_to_s(to_s) ⇒ Object
-
#initialize(object, style = nil, buffer = nil) ⇒ ToSBuilder
constructor
A new instance of ToSBuilder.
- #to_s ⇒ Object
Constructor Details
#initialize(object, style = nil, buffer = nil) ⇒ ToSBuilder
Returns a new instance of ToSBuilder.
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/commons/lang/builder/to_s_builder.rb', line 75 def initialize(object, style = nil, buffer = nil) if style == nil style = get_default_style end if buffer == nil buffer = String.new('') end @buffer = buffer @style = style @object = object style.append_start(buffer, object) end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
60 61 62 |
# File 'lib/commons/lang/builder/to_s_builder.rb', line 60 def buffer @buffer end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
60 61 62 |
# File 'lib/commons/lang/builder/to_s_builder.rb', line 60 def object @object end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
60 61 62 |
# File 'lib/commons/lang/builder/to_s_builder.rb', line 60 def style @style end |
Class Method Details
.get_default_style ⇒ Object
62 63 64 |
# File 'lib/commons/lang/builder/to_s_builder.rb', line 62 def self.get_default_style return @@default_style end |
.set_default_style(style) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/commons/lang/builder/to_s_builder.rb', line 67 def self.set_default_style(style) if style == nil raise ArgumentError, 'The style must not be nil' end @@default_style = style end |
Instance Method Details
#append(field_name, value, full_detail = true) ⇒ Object
90 91 92 93 |
# File 'lib/commons/lang/builder/to_s_builder.rb', line 90 def append(field_name, value, full_detail = true) @style.append(@buffer, field_name, value, full_detail) return self end |
#append_super(super_to_s) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/commons/lang/builder/to_s_builder.rb', line 96 def append_super(super_to_s) if super_to_s != nil @style.append_super(@buffer, super_to_s) end return self end |
#append_to_s(to_s) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/commons/lang/builder/to_s_builder.rb', line 104 def append_to_s(to_s) if to_s != nil @style.append_to_s(@buffer, to_s) end return self end |
#to_s ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/commons/lang/builder/to_s_builder.rb', line 112 def to_s if @object == nil @buffer.append(@style.get_nil_text) else @style.append_end(@buffer, @object) end return @buffer.to_s end |