Class: MdnQuery::List
- Inherits:
-
Object
- Object
- MdnQuery::List
- Defined in:
- lib/mdn_query/list.rb
Overview
A list from a search result.
Instance Attribute Summary collapse
- #items ⇒ Array<MdnQuery::Entry> readonly
-
#query ⇒ String
readonly
The query that was searched for.
Instance Method Summary collapse
-
#[](pos) ⇒ MdnQuery::Entry
Retrieves the item at the given position.
-
#each(&block) ⇒ void
Calls the given block for every item.
-
#empty? ⇒ Boolean
Returns whether the list is empty.
-
#first ⇒ MdnQuery::Entry
Returns the first item in the list.
-
#initialize(query, *items) ⇒ MdnQuery::List
constructor
Creates a new list of search results.
-
#size ⇒ Fixnum
Returns the number of items in the list.
-
#to_s ⇒ String
Returns the string representation of the list.
Constructor Details
#initialize(query, *items) ⇒ MdnQuery::List
Creates a new list of search results.
15 16 17 18 19 |
# File 'lib/mdn_query/list.rb', line 15 def initialize(query, *items) items = [] if items.nil? @query = query @items = items end |
Instance Attribute Details
#items ⇒ Array<MdnQuery::Entry> (readonly)
8 9 10 |
# File 'lib/mdn_query/list.rb', line 8 def items @items end |
#query ⇒ String (readonly)
Returns the query that was searched for.
5 6 7 |
# File 'lib/mdn_query/list.rb', line 5 def query @query end |
Instance Method Details
#[](pos) ⇒ MdnQuery::Entry
Retrieves the item at the given position.
32 33 34 |
# File 'lib/mdn_query/list.rb', line 32 def [](pos) items[pos] end |
#each(&block) ⇒ void
This method returns an undefined value.
Calls the given block for every item.
54 55 56 |
# File 'lib/mdn_query/list.rb', line 54 def each(&block) items.each(&block) end |
#empty? ⇒ Boolean
Returns whether the list is empty.
39 40 41 |
# File 'lib/mdn_query/list.rb', line 39 def empty? items.empty? end |
#first ⇒ MdnQuery::Entry
Returns the first item in the list.
24 25 26 |
# File 'lib/mdn_query/list.rb', line 24 def first items.first end |
#size ⇒ Fixnum
Returns the number of items in the list.
46 47 48 |
# File 'lib/mdn_query/list.rb', line 46 def size items.size end |
#to_s ⇒ String
Returns the string representation of the list.
61 62 63 64 |
# File 'lib/mdn_query/list.rb', line 61 def to_s return "No results for '#{query}'" if empty? "Results for '#{query}':\n#{number_items(items).join("\n")}\n" end |