Class: GContacts::List

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/google-contacts/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ List

Creates a list of Elements based on the given XML from Google



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
# File 'lib/google-contacts/list.rb', line 9

def initialize(data=nil)
  unless data
    @entries = []
    return
  end

  data = data["feed"]

  if data["entry"].is_a?(Array)
    @entries = data["entry"].map {|entry| Element.new(entry)}
  elsif data["entry"]
    @entries = [Element.new(data["entry"])]
  else
    @entries = []
  end

  if data["link"]
    data["link"].each do |link|
      if link["@rel"] == "next"
        @next_uri = URI(link["@href"])
      elsif link["@rel"] == "previous"
        @previous_uri = URI(link["@href"])
      end
    end
  end

  @id, @updated, @title, @author = data["id"], Time.parse(data["updated"]), data["title"], data["author"]
  @per_page, @start_index, @total_results = data["openSearch:itemsPerPage"].to_i, data["openSearch:startIndex"].to_i, data["openSearch:totalResults"].to_i
  @category = @entries.first.category unless @entries.empty?
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author



5
6
7
# File 'lib/google-contacts/list.rb', line 5

def author
  @author
end

#categoryObject (readonly)

Returns the value of attribute category



5
6
7
# File 'lib/google-contacts/list.rb', line 5

def category
  @category
end

#idObject (readonly)

Returns the value of attribute id



5
6
7
# File 'lib/google-contacts/list.rb', line 5

def id
  @id
end

#next_uriObject (readonly)

Returns the value of attribute next_uri



5
6
7
# File 'lib/google-contacts/list.rb', line 5

def next_uri
  @next_uri
end

#per_pageObject (readonly)

Returns the value of attribute per_page



5
6
7
# File 'lib/google-contacts/list.rb', line 5

def per_page
  @per_page
end

#previous_uriObject (readonly)

Returns the value of attribute previous_uri



5
6
7
# File 'lib/google-contacts/list.rb', line 5

def previous_uri
  @previous_uri
end

#start_indexObject (readonly)

Returns the value of attribute start_index



5
6
7
# File 'lib/google-contacts/list.rb', line 5

def start_index
  @start_index
end

#titleObject (readonly)

Returns the value of attribute title



5
6
7
# File 'lib/google-contacts/list.rb', line 5

def title
  @title
end

#total_resultsObject (readonly)

Returns the value of attribute total_results



5
6
7
# File 'lib/google-contacts/list.rb', line 5

def total_results
  @total_results
end

#updatedObject (readonly)

Returns the value of attribute updated



5
6
7
# File 'lib/google-contacts/list.rb', line 5

def updated
  @updated
end

Instance Method Details

#[](index) ⇒ Object



41
# File 'lib/google-contacts/list.rb', line 41

def [](index); @entries[index] end

#eachObject



40
# File 'lib/google-contacts/list.rb', line 40

def each; @entries.each {|e| yield e} end

#empty?Boolean



42
# File 'lib/google-contacts/list.rb', line 42

def empty?; @entries.empty? end

#lengthObject Also known as: size



43
# File 'lib/google-contacts/list.rb', line 43

def length; @entries.length end