Class: AuthorParser
- Inherits:
-
Object
- Object
- AuthorParser
- Defined in:
- lib/nexmo_developer/app/services/author_parser.rb
Constant Summary collapse
- PATH_TO_AUTHORS =
"#{Rails.configuration.blog_path}/authors/".freeze
Class Method Summary collapse
- .asset_exist?(path) ⇒ Boolean
- .fetch_all_authors ⇒ Object
- .fetch_all_blogposts_from(author) ⇒ Object
- .fetch_author(name) ⇒ Object
Class Method Details
.asset_exist?(path) ⇒ Boolean
44 45 46 47 48 49 50 |
# File 'lib/nexmo_developer/app/services/author_parser.rb', line 44 def self.asset_exist?(path) if Rails.configuration.assets.compile Rails.application.precompiled_assets.include? path else Rails.application.assets_manifest.assets[path].present? end end |
.fetch_all_authors ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nexmo_developer/app/services/author_parser.rb', line 6 def self. = {} = Dir.glob("#{PATH_TO_AUTHORS}*.json") .each do |filename| document = File.read(filename) = YAML.safe_load(document) short_name = File.basename(filename, '.json') .merge!({ 'short_name' => short_name }) [short_name.to_sym] = end end |
.fetch_all_blogposts_from(author) ⇒ Object
38 39 40 41 42 |
# File 'lib/nexmo_developer/app/services/author_parser.rb', line 38 def self.fetch_all_blogposts_from() blogposts_hash = JSON.parse(File.read(BlogpostParser::PATH_TO_INDEX)) blogposts_hash.select { |blogpost| blogpost['author'] == } end |
.fetch_author(name) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nexmo_developer/app/services/author_parser.rb', line 26 def self.(name) = "#{PATH_TO_AUTHORS}#{name}.json" return unless File.exist?() file = File.read() short_name = File.basename(, '.json') JSON.parse(file).merge!({ 'short_name' => short_name }) end |