Class: Desmoservice::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/term.rb

Direct Known Subclasses

Family, Sector, SectorTerm, TaggedTerm

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attrsObject (readonly)

Returns the value of attribute attrs.



4
5
6
# File 'lib/term.rb', line 4

def attrs
  @attrs
end

#colorObject (readonly)

Returns the value of attribute color.



4
5
6
# File 'lib/term.rb', line 4

def color
  @color
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/term.rb', line 4

def id
  @id
end

#localkeyObject (readonly)

Returns the value of attribute localkey.



4
5
6
# File 'lib/term.rb', line 4

def localkey
  @localkey
end

#parent_idObject (readonly)

Returns the value of attribute parent_id.



4
5
6
# File 'lib/term.rb', line 4

def parent_id
  @parent_id
end

#parent_localkeyObject (readonly)

Returns the value of attribute parent_localkey.



4
5
6
# File 'lib/term.rb', line 4

def parent_localkey
  @parent_localkey
end

#textObject (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

Returns:

  • (Boolean)


51
52
53
# File 'lib/term.rb', line 51

def color?
  return !@color.nil?
end

#has_attr?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


43
44
45
# File 'lib/term.rb', line 43

def localkey?
  return !@localkey.nil?
end

#text?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/term.rb', line 47

def text?
  return !@text.nil?
end