Class: BinaryParser::BitPosition
- Inherits:
-
Object
- Object
- BinaryParser::BitPosition
- Defined in:
- lib/binary_parser/general_class/bit_position.rb
Instance Attribute Summary collapse
-
#imm ⇒ Object
readonly
Returns the value of attribute imm.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
Instance Method Summary collapse
- #add_imm(length) ⇒ Object
- #add_name(name) ⇒ Object
- #eval(&name_eval_block) ⇒ Object
-
#initialize(imm = 0, names = []) ⇒ BitPosition
constructor
A new instance of BitPosition.
Constructor Details
#initialize(imm = 0, names = []) ⇒ BitPosition
Returns a new instance of BitPosition.
6 7 8 |
# File 'lib/binary_parser/general_class/bit_position.rb', line 6 def initialize(imm=0, names=[]) @imm, @names = imm, names end |
Instance Attribute Details
#imm ⇒ Object (readonly)
Returns the value of attribute imm.
4 5 6 |
# File 'lib/binary_parser/general_class/bit_position.rb', line 4 def imm @imm end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
4 5 6 |
# File 'lib/binary_parser/general_class/bit_position.rb', line 4 def names @names end |
Instance Method Details
#add_imm(length) ⇒ Object
10 11 12 |
# File 'lib/binary_parser/general_class/bit_position.rb', line 10 def add_imm(length) return BitPosition.new(@imm + length, @names) end |
#add_name(name) ⇒ Object
14 15 16 |
# File 'lib/binary_parser/general_class/bit_position.rb', line 14 def add_name(name) return BitPosition.new(@imm, @names + [Expression.length_var(name)]) end |
#eval(&name_eval_block) ⇒ Object
18 19 20 |
# File 'lib/binary_parser/general_class/bit_position.rb', line 18 def eval(&name_eval_block) return @imm + @names.inject(0){|sum, name| sum + name_eval_block.call(name)} end |