Class: Camdram::Diary

Inherits:
Base
  • Object
show all
Includes:
API
Defined in:
lib/camdram/diary.rb

Defined Under Namespace

Classes: Period, Week

Instance Attribute Summary collapse

Attributes inherited from Base

#id

Instance Method Summary collapse

Methods inherited from Base

#make_orphan

Constructor Details

#initialize(*args) ⇒ Camdram::Event

Instantiate a new Diary object from a JSON hash

Parameters:

  • options (Hash)

    A single JSON hash with symbolized keys.


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/camdram/diary.rb', line 43

def initialize(*args)
  super(*args)
  @events = split_object( @events, Event ) unless @events.nil?
  @weeks = []
  @periods = []
  @labels.each do |label|
    case label["type"]
    when "week" then
      @weeks << Week.new(label, @client_instance)
    when "period" then
      @periods << Period.new(label, @client_instance)
    end
  end
  @labels = nil
  @start_date = Date.parse(@start_date) unless @start_date.nil?
  @end_date = Date.parse(@end_date) unless @end_date.nil?
end

Instance Attribute Details

#end_dateObject

Returns the value of attribute end_date


10
11
12
# File 'lib/camdram/diary.rb', line 10

def end_date
  @end_date
end

#eventsObject

Returns the value of attribute events


10
11
12
# File 'lib/camdram/diary.rb', line 10

def events
  @events
end

#labelsObject

Returns the value of attribute labels


10
11
12
# File 'lib/camdram/diary.rb', line 10

def labels
  @labels
end

#periodsObject

Returns the value of attribute periods


10
11
12
# File 'lib/camdram/diary.rb', line 10

def periods
  @periods
end

#start_dateObject

Returns the value of attribute start_date


10
11
12
# File 'lib/camdram/diary.rb', line 10

def start_date
  @start_date
end

#weeksObject

Returns the value of attribute weeks


10
11
12
# File 'lib/camdram/diary.rb', line 10

def weeks
  @weeks
end

Instance Method Details

#infoHash

Return a hash of the diary's attributes

Returns:

  • (Hash)

    Hash with symbolized keys.


64
65
66
67
68
69
70
71
72
# File 'lib/camdram/diary.rb', line 64

def info
  {
    events: events,
    weeks: weeks,
    periods: periods,
    start_date: start_date,
    end_date: end_date,
  }
end