Class: GpisAppInfo
- Inherits:
-
Object
- Object
- GpisAppInfo
- Defined in:
- lib/gpis/gpis_app_info.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
-
#documents ⇒ Object
Returns the value of attribute documents.
-
#icon_url ⇒ Object
single value.
-
#name ⇒ Object
hashes by language.
-
#permissions ⇒ Object
Returns the value of attribute permissions.
Instance Method Summary collapse
- #fill_category_for_lang(language, document) ⇒ Object
- #fill_icon_url(document) ⇒ Object
- #fill_name_for_lang(language, document) ⇒ Object
- #fill_permissions_for_lang(language, document) ⇒ Object
- #fill_permissions_for_lang_based_on_danger_and_section_id(document, language, section_id, is_dangerous) ⇒ Object
-
#initialize(package_name, docs_by_lang_hash) ⇒ GpisAppInfo
constructor
A new instance of GpisAppInfo.
- #to_s ⇒ Object
Constructor Details
#initialize(package_name, docs_by_lang_hash) ⇒ GpisAppInfo
Returns a new instance of GpisAppInfo.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gpis/gpis_app_info.rb', line 13 def initialize(package_name, docs_by_lang_hash) @package_name = package_name @documents = docs_by_lang_hash @name = Hash.new @category = Hash.new = Hash.new # language independent values first_document = @documents[@documents.keys.first] fill_icon_url(first_document) # language specific values @documents.each do |language, document| fill_name_for_lang(language, document) fill_category_for_lang(language, document) (language, document) end end |
Instance Attribute Details
#category ⇒ Object
Returns the value of attribute category.
9 10 11 |
# File 'lib/gpis/gpis_app_info.rb', line 9 def category @category end |
#documents ⇒ Object
Returns the value of attribute documents.
8 9 10 |
# File 'lib/gpis/gpis_app_info.rb', line 8 def documents @documents end |
#icon_url ⇒ Object
single value
4 5 6 |
# File 'lib/gpis/gpis_app_info.rb', line 4 def icon_url @icon_url end |
#name ⇒ Object
hashes by language
7 8 9 |
# File 'lib/gpis/gpis_app_info.rb', line 7 def name @name end |
#permissions ⇒ Object
Returns the value of attribute permissions.
10 11 12 |
# File 'lib/gpis/gpis_app_info.rb', line 10 def end |
Instance Method Details
#fill_category_for_lang(language, document) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/gpis/gpis_app_info.rb', line 51 def fill_category_for_lang(language, document) begin @category[language] = document.css(".doc-metadata a[href^='/store/apps/category/']").inner_html rescue Exception => e raise GpisParseError.new("Gpis: Parsing Error : #{e.message} :#{e.backtrace.join("\n")}") end raise GpisParseError.new("Gpis: Parsing Error : category not found for language '#{language}'") if @category[language].nil? end |
#fill_icon_url(document) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/gpis/gpis_app_info.rb', line 32 def fill_icon_url(document) begin @icon_url = document.at_css("div.doc-banner-icon > img")['src'] rescue Exception => e raise GpisParseError.new("Gpis: Parsing Error : #{e.message} :#{e.backtrace.join("\n")}") end raise GpisParseError.new("Gpis: Parsing Error : icon not found") if @icon_url.nil? end |
#fill_name_for_lang(language, document) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/gpis/gpis_app_info.rb', line 41 def fill_name_for_lang(language, document) begin @name[language] = document.at_css("dl.doc-metadata-list span[itemprop=name]")['content'] rescue Exception => e raise GpisParseError.new("Gpis: Parsing Error : #{e.message} :#{e.backtrace.join("\n")}") end raise GpisParseError.new("Gpis: Parsing Error : name not found for language '#{language}'") if @name[language].nil? end |
#fill_permissions_for_lang(language, document) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/gpis/gpis_app_info.rb', line 92 def (language, document) #permissions are divided into two sections: dangerous and safe. They are stored in two different divs. css_selector_for_dangerous = "doc-permissions-dangerous" css_selector_for_safe = "doc-permissions-safe" (document, language, css_selector_for_dangerous, true) (document, language, css_selector_for_safe, false) end |
#fill_permissions_for_lang_based_on_danger_and_section_id(document, language, section_id, is_dangerous) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gpis/gpis_app_info.rb', line 61 def (document, language, section_id, is_dangerous) begin language_hash = [language] ||= Hash.new full_css_selector = "##{section_id} li.doc-permission-group" document.css(full_css_selector).each do |group_element| # cycle through permission groups group_name = group_element.css(".doc-permission-group-title").inner_html current_group = language_hash[group_name] #if the current_group hash hasn't yet been created, create it. All the other permissions for this group will then only be added to it, but the first one has to create it if current_group.nil? current_group = Hash.new current_group[:name] = group_name current_group[:permissions] = Array.new language_hash[group_name] = current_group end = group_element.css(".doc-permission-description").collect { |el| el.inner_html } = group_element.css(".doc-permission-description-full").collect { |el| el.inner_html } .each_index do |i| = Hash.new [:name] = [i] [:description] = [i] [:dangerous] = is_dangerous current_group[:permissions].push() end end rescue Exception => e raise GpisParseError.new("Gpis: Parsing Error : #{e.message} :#{e.backtrace.join("\n")}") end end |
#to_s ⇒ Object
100 101 102 |
# File 'lib/gpis/gpis_app_info.rb', line 100 def to_s "{Gpis App Info: name = '#{self.name}', category='#{self.category}', icon_url='#{self.icon_url}', permissions = '#{self.permissions}'}" end |