Class: WB::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/wb/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path) ⇒ Config

Returns a new instance of Config.



11
12
13
14
# File 'lib/wb/config.rb', line 11

def initialize(config_path)
  @path = config_path
  @config = YAML.safe_load(IO.read(config_path))
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/wb/config.rb', line 9

def path
  @path
end

Instance Method Details

#extensionObject



48
49
50
51
52
# File 'lib/wb/config.rb', line 48

def extension
  @extension ||= begin
    fetch_config(key: "extension", default: DEFAULT_EXTENSION_FORMAT)
  end
end

#notesObject



16
17
18
19
20
21
22
23
# File 'lib/wb/config.rb', line 16

def notes
  local_notes = Dir[File.join(WB.config.project_root, "*")]
  global_notes = [WB.config.personal_workbook, WB.config.work_workbook]

  [*local_notes, *global_notes].each_with_index.map do |note, index|
    WB::Note.new(note, index)
  end
end

#personal_workbookObject



29
30
31
# File 'lib/wb/config.rb', line 29

def personal_workbook
  @personal_workbook ||= workbook.fetch("personal")
end

#project_date_formatObject



41
42
43
44
45
46
# File 'lib/wb/config.rb', line 41

def project_date_format
  @project_date_format ||= begin
    date_format = fetch_config(key: "date_format", default: DEFAULT_DATE_FORMAT)
    Filename.generate(date_format)
  end
end

#project_rootObject



37
38
39
# File 'lib/wb/config.rb', line 37

def project_root
  @project_root ||= project.fetch("note_folder")
end

#work_workbookObject



33
34
35
# File 'lib/wb/config.rb', line 33

def work_workbook
  @work_workbook ||= workbook.fetch("work")
end

#working_hoursObject



25
26
27
# File 'lib/wb/config.rb', line 25

def working_hours
  @working_hours ||= workbook.fetch("working_hours").split("-")
end