Class: Galerts::Alert

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, options = {}) ⇒ Alert

Returns a new instance of Alert.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/galerts/alert.rb', line 4

def initialize(query, options = {})

  default_options = {
    id: 0,
    data_id: 0,
    data_id_2: 0,
    domain: DOMAIN,
    frequency: RT,
    sources: AUTOMATIC,
    language: LANGUAGE,
    how_many: ALL_RESULTS,
    region: ANYWHERE,
    delivery: RSS,
    feed_url: nil
  }

  default_options.each do |key, value|
    options[key] ||= value
  end

  # check options type
  raise "Unknown alert how many" unless HOW_MANY_TYPES.has_key?(options[:how_many])
  raise "Unknown alert delivery type" unless DELIVERY_TYPES.has_key?(options[:delivery])
  raise "Unknown alert frequency type" unless FREQ_TYPES.has_key?(options[:frequency])

  if options[:sources].kind_of?(Array)
    options[:sources].collect do |source|
      raise "Unknown alert source in Array" unless SOURCES_TYPES.has_key?(source)
    end
  elsif options[:sources].nil?
    raise "Nil alert source"
  elsif !SOURCES_TYPES.has_key?(options[:sources])
    raise "Unknown alert source"
  end

  @query = query
  @id = options[:id]
  @data_id = options[:data_id]
  @data_id_2 = options[:data_id_2]
  @domain = options[:domain]
  @frequency = options[:frequency]
  @sources = options[:sources]
  @language = options[:language]
  @how_many = options[:how_many]
  @region = options[:region]
  @delivery = options[:delivery]
  @feed_url = options[:feed_url]
end

Instance Attribute Details

#data_idObject

Returns the value of attribute data_id.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def data_id
  @data_id
end

#data_id_2Object

Returns the value of attribute data_id_2.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def data_id_2
  @data_id_2
end

#deliveryObject

Returns the value of attribute delivery.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def delivery
  @delivery
end

#domainObject

Returns the value of attribute domain.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def domain
  @domain
end

#feed_urlObject

Returns the value of attribute feed_url.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def feed_url
  @feed_url
end

#frequencyObject

Returns the value of attribute frequency.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def frequency
  @frequency
end

#how_manyObject

Returns the value of attribute how_many.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def how_many
  @how_many
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def id
  @id
end

#languageObject

Returns the value of attribute language.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def language
  @language
end

#queryObject

Returns the value of attribute query.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def query
  @query
end

#regionObject

Returns the value of attribute region.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def region
  @region
end

#sourcesObject

Returns the value of attribute sources.



3
4
5
# File 'lib/galerts/alert.rb', line 3

def sources
  @sources
end