binary_struct 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # BinaryStruct
2
2
 
3
+ [![Build Status](https://travis-ci.org/ManageIQ/binary_struct.png)](https://travis-ci.org/ManageIQ/binary_struct)
4
+ [![Code Climate](https://codeclimate.com/github/ManageIQ/binary_struct.png)](https://codeclimate.com/github/ManageIQ/binary_struct)
5
+ [![Coverage Status](https://coveralls.io/repos/ManageIQ/binary_struct/badge.png?branch=master)](https://coveralls.io/r/ManageIQ/binary_struct)
6
+
3
7
  BinaryStruct is a class for dealing with binary structured data. It simplifies
4
8
  expressing what the binary structure looks like, with the ability to name the
5
9
  parts. Given this definition, it is easy to encode/decode the binary structure
data/Rakefile CHANGED
@@ -2,4 +2,5 @@ require "bundler/gem_tasks"
2
2
 
3
3
  require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new('spec')
5
- task :test => :spec
5
+ task :test => :spec
6
+ task :default => :spec
@@ -26,4 +26,5 @@ from/to a Hash.
26
26
  spec.add_development_dependency "bundler", "~> 1.3"
27
27
  spec.add_development_dependency "rake"
28
28
  spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "coveralls"
29
30
  end
data/lib/binary_struct.rb CHANGED
@@ -131,45 +131,52 @@ class BinaryStruct
131
131
  end
132
132
 
133
133
  def self.sizeof(definition)
134
- d = @@structs_by_definition[definition]
135
- d = @@structs_by_definition[definition] = definition.kind_of?(self) ? definition : self.new(definition) if d.nil?
136
- d.size
134
+ struct_by_definition(definition).size
137
135
  end
138
136
 
139
137
  def self.decode(data, definition)
140
- d = @@structs_by_definition[definition]
141
- d = @@structs_by_definition[definition] = definition.kind_of?(self) ? definition : self.new(definition) if d.nil?
142
- d.decode(data)
138
+ struct_by_definition(definition).decode(data)
143
139
  end
144
140
 
145
141
  def self.encode(hash, definition)
146
- d = @@structs_by_definition[definition]
147
- d = @@structs_by_definition[definition] = definition.kind_of?(self) ? definition : self.new(definition) if d.nil?
148
- d.encode(hash)
142
+ struct_by_definition(definition).encode(hash)
149
143
  end
150
144
 
151
145
  private
152
146
 
147
+ def self.struct_by_definition(definition)
148
+ @@structs_by_definition[definition] ||= definition.kind_of?(self) ? definition : self.new(definition)
149
+ end
150
+
153
151
  def self.validate_definition(definition)
154
152
  raise "definition must be an array of format/name pairs" if definition.empty? || definition.length % 2 != 0
155
- definition.each_slice(2) do |format, name|
153
+ definition.each_slice(2) do |format, _|
156
154
  type, count = format[0, 1], format[1..-1]
157
- raise "unrecognized format: #{type}" unless SIZES.has_key?(type)
158
- raise "unsupported format: #{type}" if SIZES[type].nil?
159
- unless count.empty? || count == '*'
160
- begin
161
- count = Integer(count)
162
- rescue
163
- raise "unsupported count: #{count}"
164
- end
165
- raise "unsupported count: #{count}" if count < 0
166
- end
155
+ validate_definition_entry_type(type)
156
+ validate_definition_entry_count(count)
167
157
  end
168
158
  end
169
159
 
160
+ def self.validate_definition_entry_type(type)
161
+ raise "unrecognized format: #{type}" unless SIZES.has_key?(type)
162
+ raise "unsupported format: #{type}" if SIZES[type].nil?
163
+ return true
164
+ end
165
+
166
+ def self.validate_definition_entry_count(count)
167
+ return true if count.empty? || count == '*'
168
+
169
+ begin
170
+ count = Integer(count)
171
+ rescue
172
+ raise "unsupported count: #{count}"
173
+ end
174
+ raise "unsupported count: #{count}" if count < 0
175
+ end
176
+
170
177
  def self.get_size(definition)
171
178
  size = 0
172
- definition.each_slice(2) do |format, name|
179
+ definition.each_slice(2) do |format, _|
173
180
  type, count = format[0, 1], format[1..-1]
174
181
  count = count.empty? ? 1 : count.to_i
175
182
  size += (count * SIZES[type])
@@ -1,3 +1,3 @@
1
1
  class BinaryStruct
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -14,3 +14,6 @@ RSpec.configure do |config|
14
14
  # --seed 1234
15
15
  config.order = 'random'
16
16
  end
17
+
18
+ require 'coveralls'
19
+ Coveralls.wear!
data/travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-18mode
9
+ - rbx-19mode
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binary_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-16 00:00:00.000000000 Z
13
+ date: 2013-04-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -60,6 +60,22 @@ dependencies:
60
60
  - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: coveralls
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
63
79
  description: ! '
64
80
 
65
81
  BinaryStruct is a class for dealing with binary structured data. It simplifies
@@ -91,6 +107,7 @@ files:
91
107
  - spec/data/test.gif
92
108
  - spec/gif_spec.rb
93
109
  - spec/spec_helper.rb
110
+ - travis.yml
94
111
  homepage: http://github.com/ManageIQ/binary_struct
95
112
  licenses:
96
113
  - MIT
@@ -106,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
123
  version: '0'
107
124
  segments:
108
125
  - 0
109
- hash: 1202061900940413800
126
+ hash: 944965749837137154
110
127
  required_rubygems_version: !ruby/object:Gem::Requirement
111
128
  none: false
112
129
  requirements:
@@ -115,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
132
  version: '0'
116
133
  segments:
117
134
  - 0
118
- hash: 1202061900940413800
135
+ hash: 944965749837137154
119
136
  requirements: []
120
137
  rubyforge_project:
121
138
  rubygems_version: 1.8.24