Class: ANVL::Element
- Inherits:
-
Object
- Object
- ANVL::Element
- Defined in:
- lib/anvl/element.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#display_label ⇒ Object
readonly
Returns the value of attribute display_label.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #<=>(obj) ⇒ Object
- #==(obj) ⇒ Object
- #=~(str) ⇒ Object
- #[](key) ⇒ Object
-
#initialize(args) ⇒ Element
constructor
A new instance of Element.
- #push(value) ⇒ Object (also: #<<)
- #to_anvl ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args) ⇒ Element
Returns a new instance of Element.
4 5 6 7 8 9 |
# File 'lib/anvl/element.rb', line 4 def initialize args @document = args[:document] @display_label = args[:display_label] || convert_label(args[:label]) @label = convert_label(args[:label]) @value = args[:value].to_s.strip end |
Instance Attribute Details
#display_label ⇒ Object (readonly)
Returns the value of attribute display_label.
3 4 5 |
# File 'lib/anvl/element.rb', line 3 def display_label @display_label end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
3 4 5 |
# File 'lib/anvl/element.rb', line 3 def document @document end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
3 4 5 |
# File 'lib/anvl/element.rb', line 3 def label @label end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/anvl/element.rb', line 3 def value @value end |
Instance Method Details
#<=>(obj) ⇒ Object
26 27 28 |
# File 'lib/anvl/element.rb', line 26 def <=> obj @value <=> obj end |
#==(obj) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/anvl/element.rb', line 30 def == obj case obj when String return @value == obj if obj.is_a? String when Element @label == obj.label && @value = obj.display_label else false end end |
#=~(str) ⇒ Object
41 42 43 44 |
# File 'lib/anvl/element.rb', line 41 def =~ str str = str.to_s str == @label or str == @display_label or convert_label(str) == @label end |
#[](key) ⇒ Object
11 12 13 |
# File 'lib/anvl/element.rb', line 11 def [] key self.send key.to_sym end |
#push(value) ⇒ Object Also known as: <<
46 47 48 |
# File 'lib/anvl/element.rb', line 46 def push value @document.store @display_label, value, true end |
#to_anvl ⇒ Object
22 23 24 |
# File 'lib/anvl/element.rb', line 22 def to_anvl "#{@display_label || @label}:#{format_value_for_anvl}" end |
#to_s ⇒ Object
15 16 17 18 19 20 |
# File 'lib/anvl/element.rb', line 15 def to_s str = @value str &&= str.gsub(/\s*\n\s+/, ' ') str end |