Class: Bitindex::Reader
- Inherits:
-
Object
- Object
- Bitindex::Reader
- Includes:
- Common
- Defined in:
- lib/bitindex/reader.rb
Constant Summary
Constants included from Common
Common::SIGNED_16BIT, Common::SIGNED_32BIT, Common::UNSIGNED_16BIT, Common::UNSIGNED_32BIT
Instance Attribute Summary collapse
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
-
#ltor ⇒ Object
Returns the value of attribute ltor.
Instance Method Summary collapse
- #all_set(array) ⇒ Object
-
#initialize(filepath, opts = {}) ⇒ Reader
constructor
A new instance of Reader.
- #set?(value) ⇒ Boolean (also: #is_set?)
Methods included from Common
#bit_set?, #build_mask, #byte_pos, #set_bit, #unset_bit
Constructor Details
#initialize(filepath, opts = {}) ⇒ Reader
Returns a new instance of Reader.
8 9 10 11 12 13 14 |
# File 'lib/bitindex/reader.rb', line 8 def initialize filepath, opts = {} raise "#{ filepath } is not readable" unless filepath and File.readable?(filepath) @filepath = filepath @ltor = !(opts[:ltor] == false) end |
Instance Attribute Details
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
5 6 7 |
# File 'lib/bitindex/reader.rb', line 5 def filepath @filepath end |
#ltor ⇒ Object
Returns the value of attribute ltor.
6 7 8 |
# File 'lib/bitindex/reader.rb', line 6 def ltor @ltor end |
Instance Method Details
#all_set(array) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bitindex/reader.rb', line 30 def all_set array arr = [] File.open(self.filepath, 'rb') do |io| cur_idx = nil cur_byte = nil array.each do |n| idx = byte_pos n if idx < io.size if cur_idx.nil? or cur_idx < idx io.seek idx, IO::SEEK_SET cur_byte = io.getbyte end arr << n if bit_set? cur_byte, n, self.ltor end end end arr end |
#set?(value) ⇒ Boolean Also known as: is_set?
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bitindex/reader.rb', line 16 def set? value result = false File.open(self.filepath, 'rb') do |io| idx = byte_pos value if idx < io.size io.seek idx, IO::SEEK_SET result = bit_set? io.getbyte, value, self.ltor end end result end |