Class: SML::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-sml/sml-time.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value) ⇒ Time

Returns a new instance of Time.



8
9
10
11
# File 'lib/ruby-sml/sml-time.rb', line 8

def initialize(type, value)
  @type = type
  @value = value
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/ruby-sml/sml-time.rb', line 6

def type
  @type
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/ruby-sml/sml-time.rb', line 6

def value
  @value
end

Class Method Details

.construct(array_rep) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby-sml/sml-time.rb', line 13

def self.construct(array_rep)
  return nil if array_rep.nil?
  choice = array_rep.shift
  array_rep.shift unless choice.nil?
  type = case choice
         when 0x01
           :seconds_index
         when 0x02
           :timestamp
         end
  value = array_rep.shift
  array_rep.shift unless value.nil?

  return SML::Time.new(type, value)
end

.pconstruct(o = {}) ⇒ Object



29
30
31
# File 'lib/ruby-sml/sml-time.rb', line 29

def self.pconstruct(o={})
  return SML::Time.new(o[:type], o[:value])
end

Instance Method Details

#to_aObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby-sml/sml-time.rb', line 33

def to_a
  choice = case type
           when :seconds_index
             0x01
           when :timestamp
             0x02
           end

  return [] << choice << :uint8 << value << :uint32
end