Class: Desmoservice::Term
- Inherits:
-
Object
- Object
- Desmoservice::Term
- Defined in:
- lib/term.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#localkey ⇒ Object
readonly
Returns the value of attribute localkey.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
-
#parent_localkey ⇒ Object
readonly
Returns the value of attribute parent_localkey.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #color? ⇒ Boolean
- #has_attr? ⇒ Boolean
-
#initialize(data) ⇒ Term
constructor
A new instance of Term.
- #localkey? ⇒ Boolean
- #text? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ Term
Returns a new instance of Term.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/term.rb', line 6 def initialize(data) @id = data['code'] @localkey = if data.has_key?('iddesc') data['iddesc'] elsif data.has_key?('idctxt') data['idctxt'] else nil end @text = nil if data.has_key?('libelles') if data['libelles'].length > 0 @text = data['libelles'][0]['lib'] end end @color = nil if data.has_key?('familleColor') @color = data['familleColor'] end @attrs = nil if data.has_key?('attrs') @attrs = data['attrs'] end @parent_id = nil if data.has_key?('parentCode') @parent_id = data['parentCode'].to_i elsif data.has_key?('familleCode') @parent_id = data['familleCode'].to_i end @parent_localkey = nil if data.has_key?('parentIdctxt') @parent_localkey = data['parentIdctxt'] elsif data.has_key?('familleIdctxt') @parent_localkey = data['familleIdctxt'] end end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
4 5 6 |
# File 'lib/term.rb', line 4 def attrs @attrs end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
4 5 6 |
# File 'lib/term.rb', line 4 def color @color end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/term.rb', line 4 def id @id end |
#localkey ⇒ Object (readonly)
Returns the value of attribute localkey.
4 5 6 |
# File 'lib/term.rb', line 4 def localkey @localkey end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
4 5 6 |
# File 'lib/term.rb', line 4 def parent_id @parent_id end |
#parent_localkey ⇒ Object (readonly)
Returns the value of attribute parent_localkey.
4 5 6 |
# File 'lib/term.rb', line 4 def parent_localkey @parent_localkey end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
4 5 6 |
# File 'lib/term.rb', line 4 def text @text end |
Instance Method Details
#[](key) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/term.rb', line 63 def [](key) if @attrs.nil? return nil elsif !@attrs.has_key?(key) return nil else return @attrs[key] end end |
#color? ⇒ Boolean
51 52 53 |
# File 'lib/term.rb', line 51 def color? return !@color.nil? end |
#has_attr? ⇒ Boolean
55 56 57 58 59 60 61 |
# File 'lib/term.rb', line 55 def has_attr? if @attrs.nil? return false else return @attrs.has_key?(key) end end |
#localkey? ⇒ Boolean
43 44 45 |
# File 'lib/term.rb', line 43 def localkey? return !@localkey.nil? end |
#text? ⇒ Boolean
47 48 49 |
# File 'lib/term.rb', line 47 def text? return !@text.nil? end |