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.
590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'lib/geoptima/data.rb', line 590 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.
589 590 591 |
# File 'lib/geoptima/data.rb', line 589 def app_categories @app_categories end |
Instance Method Details
#[](key) ⇒ Object
605 606 607 |
# File 'lib/geoptima/data.rb', line 605 def [](key) @app_categories[key] end |
#a_to_s(a) ⇒ Object
620 621 622 |
# File 'lib/geoptima/data.rb', line 620 def a_to_s(a) (a.length > 3 ? a[0..2]+['...'] : a).join(',') end |
#app_classes ⇒ Object
614 615 616 |
# File 'lib/geoptima/data.rb', line 614 def app_classes @app_classes ||= @app_categories.values.map{|c| c.app_class}.compact.sort.uniq end |
#apps ⇒ Object
608 609 610 |
# File 'lib/geoptima/data.rb', line 608 def apps @apps ||= @app_categories.keys.compact.sort.uniq end |
#categories ⇒ Object
611 612 613 |
# File 'lib/geoptima/data.rb', line 611 def categories @categories ||= @app_categories.values.map{|c| c.category}.compact.sort.uniq end |
#describe ⇒ Object
623 624 625 |
# File 'lib/geoptima/data.rb', line 623 def describe "#{length} apps, #{categories.length} categories (#{a_to_s(categories)}), #{app_classes.length} classes (#{a_to_s(app_classes)})" end |
#length ⇒ Object
602 603 604 |
# File 'lib/geoptima/data.rb', line 602 def length @app_categories.length end |
#to_s ⇒ Object
617 618 619 |
# File 'lib/geoptima/data.rb', line 617 def to_s "#{length} apps, #{categories.length} categories, #{app_classes.length} classes" end |