Class: LimeLm::Feature

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Feature

Returns a new instance of Feature.



10
11
12
# File 'lib/lime_lm/feature.rb', line 10

def initialize(hash)
  self.send(:assign_properties, hash)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/lime_lm/feature.rb', line 8

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/lime_lm/feature.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



7
8
9
# File 'lib/lime_lm/feature.rb', line 7

def required
  @required
end

#ta_readableObject (readonly)

Returns the value of attribute ta_readable.



6
7
8
# File 'lib/lime_lm/feature.rb', line 6

def ta_readable
  @ta_readable
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/lime_lm/feature.rb', line 5

def type
  @type
end

Class Method Details

.all(params = {}) ⇒ Object



27
28
29
30
31
32
# File 'lib/lime_lm/feature.rb', line 27

def all(params={})
	version_id = params.delete(:version_id) { LimeLm.config[:version_id] }
  
  response = LimeLm::Connection.post_json({ method: 'limelm.feature.getAll', version_id: version_id })
  response['fields']['field'].map { |f| new(f) }
end

.create(params = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lime_lm/feature.rb', line 15

def create(params={})
  version_id = params.delete(:version_id) { LimeLm.config[:version_id] }

  response = LimeLm::Connection.post_json({ method: 'limelm.feature.add', version_id: version_id }.merge!(params))
  additional_info = LimeLm::Utils.stringify_keys(params)
  additional_info['type'] = 'string' unless additional_info['type'] 
  additional_info['required'] = 'true' unless additional_info['required']
  additional_info['ta_readable'] = 'true' unless additional_info['ta_readable']

  new(response['feature'].merge!(additional_info))
end

Instance Method Details

#destroy!Object



45
46
47
48
# File 'lib/lime_lm/feature.rb', line 45

def destroy!
  LimeLm::Connection.post_json({ method: 'limelm.feature.delete', feature_id: @id })
  true
end

#update!(params = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/lime_lm/feature.rb', line 35

def update!(params={})
  response = LimeLm::Connection.post_json({ method: 'limelm.feature.edit', feature_id: @id }.merge!(params))
  new_info = LimeLm::Utils.stringify_keys(params)
  @name        = new_info['name'] if new_info['name']
  @ta_readable = (new_info['ta_readable'] == 'true') if new_info['ta_readable']
  @required    = (new_info['required'] == 'true') if new_info['required']
  @description = new_info['description'] if new_info['description']
  true
end