Skip to content

Commit

Permalink
Merge pull request #458 from jugglinmike/items-by-regex
Browse files Browse the repository at this point in the history
Support filtering Items Arrays by Regex
  • Loading branch information
denisdefreyne committed Aug 10, 2014
2 parents db1db13 + bb4a6c0 commit 93d5499
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/nanoc/base/source_data/item_array.rb
Expand Up @@ -34,6 +34,8 @@ def freeze
def [](*args)
if 1 == args.size && args.first.is_a?(String)
item_with_identifier(args.first)
elsif 1 == args.size && args.first.is_a?(Regexp)
@items.select { |i| i.identifier =~ args.first }
else
@items[*args]
end
Expand Down
8 changes: 8 additions & 0 deletions test/base/test_item_array.rb
Expand Up @@ -97,6 +97,14 @@ def test_brackets_and_slice_and_at_frozen
assert_nil @items.at('/tenthousand/')
end

def test_regex
foo = Nanoc::Item.new('Item Foo', {}, '/foo/')
@items << foo

assert_equal [@one], @items[/n/]
assert_equal [@two, foo], @items[%r{o/}]
end

def test_less_than_less_than
assert_nil @items[2]
assert_nil @items['/foo/']
Expand Down

0 comments on commit 93d5499

Please sign in to comment.