Class: Alien::AlienTagList
- Inherits:
-
Array
- Object
- Array
- Alien::AlienTagList
- Defined in:
- lib/alien/alientaglist.rb
Instance Method Summary collapse
-
#add_tag(t) ⇒ Object
Adds an AlienTag to the list.
-
#filter(filter) ⇒ Object
A little regular expression scanner.
-
#filter!(filter) ⇒ Object
A self-modifying version of filter_taglist.
-
#initialize(taglist_string = "") ⇒ AlienTagList
constructor
A new instance of AlienTagList.
-
#string_to_taglist(taglist_string) ⇒ Object
Takes a taglist string from a reader and appends it to the array.
Constructor Details
#initialize(taglist_string = "") ⇒ AlienTagList
Returns a new instance of AlienTagList.
17 18 19 20 |
# File 'lib/alien/alientaglist.rb', line 17 def initialize(taglist_string="") super() string_to_taglist(taglist_string) if taglist_string != "" end |
Instance Method Details
#add_tag(t) ⇒ Object
Adds an AlienTag to the list.
37 38 39 40 |
# File 'lib/alien/alientaglist.rb', line 37 def add_tag(t) self.push(t) return self end |
#filter(filter) ⇒ Object
A little regular expression scanner. Looks at the list of tags and returns a new taglist containing those tag IDs that match a regular expression filter.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/alien/alientaglist.rb', line 44 def filter(filter) tl = AlienTagList.new self.each do |ele| if ele.tag =~ filter tl.add_tag(ele) end end return tl end |
#filter!(filter) ⇒ Object
A self-modifying version of filter_taglist. Excercise caution. Elements in the taglist array that do not match the regular expression are deleted.
59 60 61 62 |
# File 'lib/alien/alientaglist.rb', line 59 def filter!(filter) self.delete_if { |ele| !(ele.tag =~ filter)} return self end |
#string_to_taglist(taglist_string) ⇒ Object
Takes a taglist string from a reader and appends it to the array.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/alien/alientaglist.rb', line 24 def string_to_taglist(taglist_string) lines = taglist_string.split("\r\n") lines.each do |line| if line != "(No Tags)" add_tag(AlienTag.new(line)) end end return self end |