Class: Tagline::TagStorer
- Inherits:
-
Object
- Object
- Tagline::TagStorer
- Defined in:
- lib/tagline/tag_storer.rb
Instance Method Summary collapse
-
#initialize(filename, lines) ⇒ TagStorer
constructor
A new instance of TagStorer.
- #retrieve_stored_tags ⇒ Object
- #save_tags ⇒ Object
Constructor Details
#initialize(filename, lines) ⇒ TagStorer
Returns a new instance of TagStorer.
3 4 5 |
# File 'lib/tagline/tag_storer.rb', line 3 def initialize(filename, lines) @filename, @lines = filename, lines end |
Instance Method Details
#retrieve_stored_tags ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/tagline/tag_storer.rb', line 7 def tag_names.each do |tag| next unless File.exist?(tag_filename(tag)) tagged_lines = File.read(tag_filename(tag)).split("\n") lines.each { |line| line[tag] = tagged_lines.include?(line.text) } end end |
#save_tags ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/tagline/tag_storer.rb', line 15 def tag_names.each do |tag| tagged_lines = lines.select { |line| line[tag] }.map(&:text) next if tagged_lines.empty? File.write(tag_filename(tag), tagged_lines.join("\n")) end end |