Class: Fantassh::Entries
- Inherits:
-
Object
- Object
- Fantassh::Entries
- Defined in:
- lib/fantassh/entries.rb
Instance Attribute Summary collapse
-
#entries_file ⇒ Object
readonly
Returns the value of attribute entries_file.
Instance Method Summary collapse
- #add(new_entries) ⇒ Object
- #all ⇒ Object
- #excluded ⇒ Object
- #init_file_structure ⇒ Object
-
#initialize(config_dir: nil) ⇒ Entries
constructor
A new instance of Entries.
Constructor Details
#initialize(config_dir: nil) ⇒ Entries
Returns a new instance of Entries.
7 8 9 10 11 12 |
# File 'lib/fantassh/entries.rb', line 7 def initialize(config_dir: nil) @config_dir = config_dir || File.join(Dir.home, '.fantassh') @entries_file = File.join(@config_dir, 'entries') @excluded_entries_file = File.join(@config_dir, 'excluded_entries') init_file_structure end |
Instance Attribute Details
#entries_file ⇒ Object (readonly)
Returns the value of attribute entries_file.
5 6 7 |
# File 'lib/fantassh/entries.rb', line 5 def entries_file @entries_file end |
Instance Method Details
#add(new_entries) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/fantassh/entries.rb', line 22 def add(new_entries) new_entries = new_entries.map(&:strip).delete_if { |x| x.empty? } entries = (all + new_entries).uniq - excluded File.open(@entries_file, 'w') do |f| f.puts(entries) end end |
#all ⇒ Object
14 15 16 |
# File 'lib/fantassh/entries.rb', line 14 def all File.readlines(@entries_file).map(&:strip) end |
#excluded ⇒ Object
18 19 20 |
# File 'lib/fantassh/entries.rb', line 18 def excluded File.readlines(@excluded_entries_file).map(&:strip) end |
#init_file_structure ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/fantassh/entries.rb', line 31 def init_file_structure unless Dir.exist?(@config_dir) FileUtils.mkdir(@config_dir) end FileUtils.touch(@entries_file) FileUtils.touch(@excluded_entries_file) end |