Class: ShareWith::ServiceDataType::BasicDataType

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

Overview

This works as an abstract class to inherit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ BasicDataType

Returns a new instance of BasicDataType.



15
16
17
18
19
# File 'lib/share_with/service_data.rb', line 15

def initialize(data)
  @data = data
  @default = data[:default]
  @value = @default
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



12
13
14
# File 'lib/share_with/service_data.rb', line 12

def label
  @label
end

#value(encoding = nil) ⇒ Object



21
22
23
24
25
26
# File 'lib/share_with/service_data.rb', line 21

def value(encoding = nil)
  res = @value || @default || ""
  res = res.send(encoding.to_sym) unless encoding.nil?

  res
end

Instance Method Details

#attr(attr_value) ⇒ Object



28
29
30
# File 'lib/share_with/service_data.rb', line 28

def attr(attr_value)
  @data[:attr][attr_value]
end

#reset!Object



32
33
34
# File 'lib/share_with/service_data.rb', line 32

def reset!
  self.value = @default
end