Class: LibBin::DataRange

Inherits:
Object
  • Object
show all
Defined in:
lib/libbin/data_types.rb,
ext/libbin/libbin_c.c

Overview

Classs that can be used to get the shape of a Structure or of a Structure::Scalar.

Direct Known Subclasses

DataShape

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min, max) ⇒ DataShape #initialize(members) ⇒ DataShape

Returns a new instance of DataRange.

Overloads:

  • #initialize(min, max) ⇒ DataShape

    Create a new shape starting and min and ending at max. This shape has no members.

    Parameters:

    • min (Integer)

      start of the shape

    • max (Integer)

      end of the shape

  • #initialize(members) ⇒ DataShape

    Creates a new shape by reducing the shape of it’s memebers.

    Parameters:

    • members (DataShape)

      the members composing the shape



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/libbin/data_types.rb', line 32

def initialize(*args)
  if args.length == 2
    @range = Range::new(args[0], args[1])
  else
    if args[0].kind_of?(Hash)
      @range = args[0].values.compact.collect(&:range).reduce(:+)
    else
      @range = args[0].compact.collect(&:range).reduce(:+)
    end
  end
end

Instance Attribute Details

#rangeObject (readonly)

Returns the value of attribute range.



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

def range
  @range
end

Instance Method Details

#firstInteger

Return the beginning of the shape

Returns:

  • (Integer)


46
47
48
# File 'lib/libbin/data_types.rb', line 46

def first
  @range.first
end

#lastInteger

Return the end of the shape

Returns:

  • (Integer)


52
53
54
# File 'lib/libbin/data_types.rb', line 52

def last
  @range.last
end

#sizeInteger

Return the size of the shape

Returns:

  • (Integer)


58
59
60
# File 'lib/libbin/data_types.rb', line 58

def size
  @range.size
end