Class: ModelFormatting::Part
- Inherits:
-
Array
- Object
- Array
- ModelFormatting::Part
- Defined in:
- lib/model_formatting.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
- #<<(s) ⇒ Object
- #==(other) ⇒ Object
- #compact! ⇒ Object
- #formatted_string ⇒ Object
-
#initialize(format, *args) ⇒ Part
constructor
A new instance of Part.
- #inspect ⇒ Object
- #simple_string ⇒ Object
Constructor Details
#initialize(format, *args) ⇒ Part
Returns a new instance of Part.
7 8 9 10 11 |
# File 'lib/model_formatting.rb', line 7 def initialize(format, *args) @format = format @simple_string = @formatted_string = nil super(*args) end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
6 7 8 |
# File 'lib/model_formatting.rb', line 6 def format @format end |
Instance Method Details
#<<(s) ⇒ Object
13 14 15 16 |
# File 'lib/model_formatting.rb', line 13 def <<(s) @simple_string = @formatted_string = nil super end |
#==(other) ⇒ Object
37 38 39 |
# File 'lib/model_formatting.rb', line 37 def ==(other) simple_string == other end |
#compact! ⇒ Object
18 19 20 21 |
# File 'lib/model_formatting.rb', line 18 def compact! @simple_string = @formatted_string = nil super end |
#formatted_string ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/model_formatting.rb', line 27 def formatted_string @formatted_string ||= begin if @format == :html %(<pre><code#{%( class="#{@class_name}") unless @class_name.blank?}>#{simple_string}</code></pre>) else simple_string end end end |
#inspect ⇒ Object
41 42 43 |
# File 'lib/model_formatting.rb', line 41 def inspect "#{self.class.name}: #{simple_string.inspect}" end |
#simple_string ⇒ Object
23 24 25 |
# File 'lib/model_formatting.rb', line 23 def simple_string @simple_string ||= join("\n") end |