Class: DroneApi::Strike

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Strike

Initialize attributes



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
52
53
54
# File 'lib/drone_api/strike.rb', line 27

def initialize(data = nil)
  unless data.nil?
    data = JSON.parse(data) if data.is_a? String

     @id = parse_string(data['_id'])
     @number = parse_int(data['number'])
     @country = parse_string(data['country'])
     @date = parse_date(data['date'])
     @town = parse_string(data['town'])
     @location = parse_string(data['location'])
     @deaths = parse_int(data['deaths'])
     @deaths_min = parse_int(data['deaths_min'])
     @deaths_max = parse_int(data['deaths_max'])
     @civilians = parse_int(data['civilians'])
     @injuries = parse_int(data['injuries'])
     @children = parse_int(data['children'])
     @tweet_id = parse_string(data['tweet_id'])
     @bureau_id = parse_string(data['bureau_id'])
     @summary_short = parse_string(data['bij_summary_short'])
     @link = parse_string(data['bij_link'])
     @target = parse_string(data['target'])
     @lat = parse_string(data['lat'])
     @lon = parse_string(data['lon'])
     @articles = parse_string(data['articles'])
     @names = parse_string(data['names'])

  end
end

Instance Attribute Details

#articlesObject (readonly)

Returns the value of attribute articles.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def articles
  @articles
end

Returns the value of attribute bij_link.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def bij_link
  @bij_link
end

#bij_summary_shortObject (readonly)

Returns the value of attribute bij_summary_short.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def bij_summary_short
  @bij_summary_short
end

#bureau_idObject (readonly)

Returns the value of attribute bureau_id.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def bureau_id
  @bureau_id
end

#childrenObject (readonly)

Returns the value of attribute children.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def children
  @children
end

#civiliansObject (readonly)

Returns the value of attribute civilians.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def civilians
  @civilians
end

#countryObject (readonly)

Returns the value of attribute country.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def country
  @country
end

#dateObject (readonly)

Returns the value of attribute date.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def date
  @date
end

#deathsObject (readonly)

Returns the value of attribute deaths.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def deaths
  @deaths
end

#deaths_maxObject (readonly)

Returns the value of attribute deaths_max.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def deaths_max
  @deaths_max
end

#deaths_minObject (readonly)

Returns the value of attribute deaths_min.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def deaths_min
  @deaths_min
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def id
  @id
end

#injuriesObject (readonly)

Returns the value of attribute injuries.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def injuries
  @injuries
end

#latObject (readonly)

Returns the value of attribute lat.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def lat
  @lat
end

#locationObject (readonly)

Returns the value of attribute location.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def location
  @location
end

#lonObject (readonly)

Returns the value of attribute lon.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def lon
  @lon
end

#namesObject (readonly)

Returns the value of attribute names.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def names
  @names
end

#numberObject (readonly)

Returns the value of attribute number.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def number
  @number
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def target
  @target
end

#townObject (readonly)

Returns the value of attribute town.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def town
  @town
end

#tweet_idObject (readonly)

Returns the value of attribute tweet_id.



6
7
8
# File 'lib/drone_api/strike.rb', line 6

def tweet_id
  @tweet_id
end

Class Method Details

.parse(js) ⇒ Object

Return array of Strike objects from json string



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/drone_api/strike.rb', line 13

def self.parse(js)
  data = JSON.parse(js)
  strikes = []

  data['strike'].each  do |s|
    strike = Strike.new s
    strikes << strike
  end unless data['strike'].nil? or data['strike'].empty?

  return strikes
end