Class: Geoptima::AppCategories
- Inherits:
-
Object
- Object
- Geoptima::AppCategories
- Defined in:
- lib/geoptima/data.rb
Instance Attribute Summary collapse
-
#app_categories ⇒ Object
readonly
Returns the value of attribute app_categories.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #a_to_s(a) ⇒ Object
- #app_classes ⇒ Object
- #apps ⇒ Object
- #categories ⇒ Object
- #describe ⇒ Object
-
#initialize(path) ⇒ AppCategories
constructor
A new instance of AppCategories.
- #length ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ AppCategories
Returns a new instance of AppCategories.
597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/geoptima/data.rb', line 597 def initialize(path) begin @app_categories = File.open(path).inject({}) do |a,l| f=l.chomp.split(/\,/).map{|v| v.gsub(/^\s+/,'').gsub(/\s+$/,'')} a[f[0]] = AppCategory.new(*f) unless(f[0] =~ /appName.unique/i) a end rescue puts "Failed to load app categories from '#{path}': #{$!}" @app_categories = {} end end |
Instance Attribute Details
#app_categories ⇒ Object (readonly)
Returns the value of attribute app_categories.
596 597 598 |
# File 'lib/geoptima/data.rb', line 596 def app_categories @app_categories end |
Instance Method Details
#[](key) ⇒ Object
612 613 614 |
# File 'lib/geoptima/data.rb', line 612 def [](key) @app_categories[key] end |
#a_to_s(a) ⇒ Object
627 628 629 |
# File 'lib/geoptima/data.rb', line 627 def a_to_s(a) (a.length > 3 ? a[0..2]+['...'] : a).join(',') end |
#app_classes ⇒ Object
621 622 623 |
# File 'lib/geoptima/data.rb', line 621 def app_classes @app_classes ||= @app_categories.values.map{|c| c.app_class}.compact.sort.uniq end |
#apps ⇒ Object
615 616 617 |
# File 'lib/geoptima/data.rb', line 615 def apps @apps ||= @app_categories.keys.compact.sort.uniq end |
#categories ⇒ Object
618 619 620 |
# File 'lib/geoptima/data.rb', line 618 def categories @categories ||= @app_categories.values.map{|c| c.category}.compact.sort.uniq end |
#describe ⇒ Object
630 631 632 |
# File 'lib/geoptima/data.rb', line 630 def describe "#{length} apps, #{categories.length} categories (#{a_to_s(categories)}), #{app_classes.length} classes (#{a_to_s(app_classes)})" end |
#length ⇒ Object
609 610 611 |
# File 'lib/geoptima/data.rb', line 609 def length @app_categories.length end |
#to_s ⇒ Object
624 625 626 |
# File 'lib/geoptima/data.rb', line 624 def to_s "#{length} apps, #{categories.length} categories, #{app_classes.length} classes" end |