Class: LibBin::DataShape

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ DataShape

Returns a new instance of DataShape.



23
24
25
26
27
28
29
30
31
# File 'lib/libbin/data_types.rb', line 23

def initialize(*args)
  if args.length == 2
    @range = Range::new(args[0], args[1])
    @members = nil
  else
    @members = args[0]
    @range = @members.values.flatten.compact.collect(&:range).reduce { |memo, obj| memo + obj }
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *arg, &block) ⇒ Object



18
19
20
21
# File 'lib/libbin/data_types.rb', line 18

def method_missing(m, *arg, &block)
  return @members[m] if @members && @members[m]
  super
end

Instance Attribute Details

#membersObject (readonly)

Returns the value of attribute members.



16
17
18
# File 'lib/libbin/data_types.rb', line 16

def members
  @members
end

#rangeObject (readonly)

Returns the value of attribute range.



15
16
17
# File 'lib/libbin/data_types.rb', line 15

def range
  @range
end

Instance Method Details

#firstObject



33
34
35
# File 'lib/libbin/data_types.rb', line 33

def first
  @range.first
end

#lastObject



37
38
39
# File 'lib/libbin/data_types.rb', line 37

def last
  @range.last
end

#sizeObject



41
42
43
# File 'lib/libbin/data_types.rb', line 41

def size
  @range.size
end