Class: TimelineSource

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

Overview

Creates the json data for a Simile timeline.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TimelineSource

Create a new timeline source. There are several ways to fill this with data:

raw_data

The most straightforward method is to pass the :raw_data option which must contain an array containing each event on the timeline as a hash. Each event must at least contain the :start (start date), :title (Event title). Other than that, all, options that are valid for the simile timeline events will be accepted.

sources

The :sources option must contain a list of ActiveSource objects. By default this will try to take the dcns:date property from all objects.

source_finder

Alternatively, you may pass the :source_finder option. This option should contain a hash that will be passed into ActiveSource.find(:all)

Other options that can be used to configure the working of the timeline data source are:

start_property

Only valid with the :sources or :source_finder option. The class will try to retrieve the start date from this property. If an ISO 8601 duration is found in the field a duration event is created (unless an :end_property had been explicitly set). [default: dcns:date]

end_property

Take the end date of each event from this property. This will disable the automatic handling of ISO 8601 durations (see :start_property)

title_property

Take the event title from this property. If the title is not found, the system will try the dcns:label property and if that fails use the local part of the source URL. This is only valid with the :sources or :source_finder options. [default: dcns:title]

description_property

Take the description of the event from this field. If not found, the title value is used. This is only valid with the :sources or :source_finder options. [default: dcns:abstract]

link_property

Property to take the link from. By default a link to the element’s own URL is created. This is only valid with the :sources or :source_finder options.

color

Default color entry for the events. [default: ‘blue’]

text_color

Default text color for the events [default: ‘black’]

start_year

Year that the timeline starts in. If not given, this will automatically be calculated from the dataset

final_year

Last year of the timeline. See :start_year



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/timeline_source.rb', line 52

def initialize(options)
  @events = []
  @options = process_options(options)
  
  if(@options[:sources])
    initialize_from_sources(options[:sources])
  elsif(@options[:source_finder])
    sources = TaliaCore::ActiveSource.find(:all, @options[:source_finder])
    initialize_from_sources(sources)
  else
    initialize_from_data(@options[:raw_data])
  end
  @first_year = @options[:start_year] if(@options[:start_year])
  @last_year = @options[:final_year] if(@options[:final_year])
end

Class Method Details

.to_iso8601(date) ⇒ Object

Get the iso8601 string for the date



84
85
86
87
# File 'lib/timeline_source.rb', line 84

def self.to_iso8601(date)
  return nil unless(date)
  date.strftime('%Y-%m-%dT%H:%M:%SZ')
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/timeline_source.rb', line 89

def empty?
  @events.empty?
end

#first_yearObject



68
69
70
# File 'lib/timeline_source.rb', line 68

def first_year
  (@first_year || '1900').to_i
end

#last_yearObject



72
73
74
# File 'lib/timeline_source.rb', line 72

def last_year
  (@last_year || '2000').to_i
end

#timeline_dataObject



76
77
78
79
80
81
# File 'lib/timeline_source.rb', line 76

def timeline_data
  {
    :dateTimeFormat => 'iso8601',
    :events => @events
  }.to_json
end