Class: Evertils::Helper::Formatting

Inherits:
Object
  • Object
show all
Defined in:
lib/evertils/helpers/formatting.rb

Instance Method Summary collapse

Instance Method Details

#date_templatesObject

Template string for note title



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/evertils/helpers/formatting.rb', line 39

def date_templates
  current_date = Date.today
  week_stub = day_of_week(current_date.strftime('%a'))
  start_of_week = Date.commercial(current_date.year, current_date.cweek, 1)
  end_of_week = Date.commercial(current_date.year, current_date.cweek, 5)

  {
    :Daily => "Daily Log [#{current_date.strftime('%B %-d')} - #{week_stub}]",
    :Weekly => "Weekly Log [#{start_of_week.strftime('%B %-d')} - #{end_of_week.strftime('%B %-d')}]",
    :Monthly => "Monthly Log [#{current_date.strftime('%B %Y')}]",
    :Deployments => "#{current_date.strftime('%B %-d')} - #{week_stub}",
    :'Priority Queue' => "Queue For [#{current_date.strftime('%B %-d')} - #{week_stub}]"
  }
end

#day_of_week(arg_date = Date.today.strftime('%a')) ⇒ Object

Legacy notes will have single/double character denotations for day of week, this maps them.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/evertils/helpers/formatting.rb', line 6

def day_of_week(arg_date = Date.today.strftime('%a'))
  case arg_date
  when 'Mon'
    :M
  when 'Tue'
    :Tu
  when 'Wed'
    :W
  when 'Thu'
    :Th
  when 'Fri'
    :F
  when 'Sat'
    :Sa
  when 'Sun'
    :Su
  end
end

#symbolize(h) ⇒ Object

Recursively symbolize keys in a hash Params:

h

The hash you want to symbolize



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/evertils/helpers/formatting.rb', line 57

def symbolize(h)
  case h
  when Hash
    Hash[
      h.map do |k, v|
        [k.respond_to?(:to_sym) ? k.to_sym : k, symbolize(v)]
      end
    ]
  when Enumerable
    h.map { |v| symbolize(v) }
  else
    h
  end
end

#template_contents(type = nil) ⇒ Object

Template file for note body



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/evertils/helpers/formatting.rb', line 26

def template_contents(type = nil)
  begin
    raise ArgumentError, "Type is required" if type.nil?

    IO.readlines(load_template(type), :encoding => 'UTF-8').join("").delete!("\n")
  rescue Errno::ENOENT => e
    Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false)
  rescue ArgumentError => e
    Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false)
  end
end