class Tagline::TagStorer

Attributes

filename[R]
lines[R]

Public Class Methods

new(filename, lines) click to toggle source
# File lib/tagline/tag_storer.rb, line 3
def initialize(filename, lines)
  @filename, @lines = filename, lines
end

Public Instance Methods

retrieve_stored_tags() click to toggle source
# File lib/tagline/tag_storer.rb, line 7
def retrieve_stored_tags
  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() click to toggle source
# File lib/tagline/tag_storer.rb, line 15
def save_tags
  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

Private Instance Methods

file_ext() click to toggle source
# File lib/tagline/tag_storer.rb, line 31
def file_ext
  @file_ext ||= File.extname(filename)
end
file_without_ext() click to toggle source
# File lib/tagline/tag_storer.rb, line 35
def file_without_ext
  @file_without_ext ||= filename.chomp(file_ext)
end
tag_filename(tag) click to toggle source
# File lib/tagline/tag_storer.rb, line 39
def tag_filename(tag)
  "#{file_without_ext}_#{tag}#{file_ext}"
end
tag_names() click to toggle source
# File lib/tagline/tag_storer.rb, line 27
def tag_names
  @tag_names ||= Tagline.tags.keys
end