Class: Trendhub::Language
- Inherits:
-
Object
- Object
- Trendhub::Language
- Defined in:
- lib/trendhub/language.rb
Instance Attribute Summary collapse
-
#language_path ⇒ Object
readonly
Returns the value of attribute language_path.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize ⇒ Language
constructor
A new instance of Language.
- #update ⇒ Object
Constructor Details
#initialize ⇒ Language
Returns a new instance of Language.
7 8 9 |
# File 'lib/trendhub/language.rb', line 7 def initialize @language_path = "#{Trendhub.root}/data/languages" end |
Instance Attribute Details
#language_path ⇒ Object (readonly)
Returns the value of attribute language_path.
5 6 7 |
# File 'lib/trendhub/language.rb', line 5 def language_path @language_path end |
Instance Method Details
#all ⇒ Object
11 12 13 |
# File 'lib/trendhub/language.rb', line 11 def all File.read(language_path).split("\n") end |
#update ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/trendhub/language.rb', line 15 def update require 'http' require 'yaml' language_url = "https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml" response = HTTP.get(language_url) languages = YAML.load(response.to_s).keys.map do |language| language.downcase.gsub(" ", "-") end File.write(language_path, languages.join("\n")) end |