Class: Evertils::Common::Entity::Base

Inherits:
Generic
  • Object
show all
Defined in:
lib/evertils/common/entity.rb

Overview

Since:

  • 0.3.0

Direct Known Subclasses

Note, Notebook, Notebooks, Notes, Stack, Sync, Tag, Tags

Constant Summary collapse

REPLACEMENTS =

Since:

  • 0.3.0

{
  '%DOY%': Date.today.yday,
  '%MONTH_NAME%': Date.today.strftime('%B'),
  '%MONTH%': Date.today.month,
  '%DAY%': Date.today.day,
  '%DOW%': Date.today.wday,
  '%DOW_NAME%': Date.today.strftime('%a'),
  '%YEAR%': Date.today.year,
  '%WEEK%': Date.today.cweek,
  '%WEEK_START%': Date.commercial(Date.today.year, Date.today.cweek, 1),
  '%WEEK_END%': Date.commercial(Date.today.year, Date.today.cweek, 5)
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#bytesize, #deprecation_notice, #encoding, #force_encoding, #has_required_fields

Constructor Details

#initializeBase

Returns a new instance of Base.

Since:

  • 0.3.0



20
21
22
23
24
# File 'lib/evertils/common/entity.rb', line 20

def initialize
  @evernote = Authentication.instance

  super
end

Instance Attribute Details

#entityObject

Since:

  • 0.3.0



5
6
7
# File 'lib/evertils/common/entity.rb', line 5

def entity
  @entity
end

Instance Method Details

#end_of_day(date = ::Time.now) ⇒ Object

Since:

  • 0.2.8



60
61
62
# File 'lib/evertils/common/entity.rb', line 60

def end_of_day(date = ::Time.now)
  ::Time.mktime(date.year, date.month, date.day, 23, 59, 59, 0).to_datetime
end

#placeholders_for(items) ⇒ Object

Since:

  • 0.3.0



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

def placeholders_for(items)
  items.map do |item|
    REPLACEMENTS.each_pair do |k, v|
      item.last.gsub!(k.to_s, v.to_s) if item.last.is_a? String
      item.last.map { |i| i.gsub!(k.to_s, v.to_s) } if item.last.is_a? Array
    end
  end

  symbolize_keys(items)
end

#prop(name) ⇒ Object

Since:

  • 0.2.9



66
67
68
# File 'lib/evertils/common/entity.rb', line 66

def prop(name)
  @entity.send(name)
end

#start_of_day(date = ::Time.now) ⇒ Object

Since:

  • 0.2.8



54
55
56
# File 'lib/evertils/common/entity.rb', line 54

def start_of_day(date = ::Time.now)
  ::Time.mktime(date.year, date.month, date.day, 12, 0, 0, 0, 0).to_datetime
end

#symbolize_keys(hash) ⇒ Object

Since:

  • 0.3.0



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/evertils/common/entity.rb', line 37

def symbolize_keys(hash)
  hash.inject({}){ |result, (key, value)|
    new_key = case key
              when String then key.to_sym
              else key
              end
    new_value = case value
                when Hash then symbolize_keys(value)
                else value
                end
    result[new_key] = new_value
    result
  }
end

#to_sObject

Since:

  • 0.3.2



72
73
74
# File 'lib/evertils/common/entity.rb', line 72

def to_s
  prop(:guid)
end