Skip to content

Commit

Permalink
Allow .bom to support multiple lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejholmes committed Apr 26, 2012
1 parent bf8642a commit ec2b691
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -76,11 +76,14 @@ Octopart::Part.match('texas instruments', 'SN74LS240N')

**#bom**

Return an array of parts that match the criteria
Return an array of parts for each line specified.

```ruby
Octopart::Part.bom(mpn: 'SN74LS240N')
# => [<Octopart::Part >, ... ]
# => [[<Octopart::Part >, ... ]]

Octopart::Part.bom([{mpn: 'SN74LS240N'}, {mpn: 'ATMEGA328P-PU'}])
# => [[<Octopart::Part >, ... ], [<Octopart::Part >, ... ]]
```

## Contributing
Expand Down
3 changes: 1 addition & 2 deletions lib/octopart/part.rb
Expand Up @@ -80,8 +80,7 @@ def match(manufacturer, mpn)
def bom(lines)
lines = [lines] unless lines.is_a?(Array)
response = JSON.parse(self.get('bom/match', lines: lines.to_json))
parts = response['results'].first['items']
self.build(parts)
response['results'].map { |line| self.build(line['items']) }
end

# Internal: Converts a Hash or an Array of Hash into an Octopart::Part or
Expand Down
9 changes: 7 additions & 2 deletions spec/lib/part_spec.rb
Expand Up @@ -57,8 +57,13 @@
subject { described_class.bom(mpn: 'SN74LS240N') }

it { should be_a(Array) }
it "each object in the array should be a part" do
subject.each { |part| part.should be_a(Octopart::Part) }
it "each object in the array should be an array part" do
subject.each do |line|
line.should be_a(Array)
line.each do |part|
part.should be_a(Octopart::Part)
end
end
end
end
end
Expand Down

0 comments on commit ec2b691

Please sign in to comment.