Class: CategoryParser
- Inherits:
-
Object
- Object
- CategoryParser
- Defined in:
- lib/nexmo_developer/app/services/category_parser.rb
Constant Summary collapse
- PATH_TO_CATEGORIES =
"#{Rails.configuration.blog_path}/categories.json".freeze
Class Method Summary collapse
- .fetch_all_categories ⇒ Object
- .fetch_blogposts_with_category(category) ⇒ Object
- .fetch_category(slug) ⇒ Object
Class Method Details
.fetch_all_categories ⇒ Object
6 7 8 |
# File 'lib/nexmo_developer/app/services/category_parser.rb', line 6 def self.fetch_all_categories JSON.parse(File.read(PATH_TO_CATEGORIES))['categories'] end |
.fetch_blogposts_with_category(category) ⇒ Object
14 15 16 17 18 |
# File 'lib/nexmo_developer/app/services/category_parser.rb', line 14 def self.fetch_blogposts_with_category(category) blogposts_hash = JSON.parse(File.read(BlogpostParser::PATH_TO_INDEX)) blogposts_hash.select { |blogpost| blogpost['category'] == category } end |
.fetch_category(slug) ⇒ Object
10 11 12 |
# File 'lib/nexmo_developer/app/services/category_parser.rb', line 10 def self.fetch_category(slug) fetch_all_categories.find { |c| c['slug'] == slug.downcase } end |