Class: CreativeCommonsRails::LicenseInfo
- Inherits:
-
Object
- Object
- CreativeCommonsRails::LicenseInfo
- Defined in:
- lib/creative_commons_rails/license_info.rb
Instance Attribute Summary collapse
-
#jurisdiction ⇒ Object
Returns the value of attribute jurisdiction.
-
#type ⇒ Object
Returns the value of attribute type.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.find(attributes = {}) ⇒ Object
ensure the license exists in the license index.
- .license_index ⇒ Object
Instance Method Summary collapse
- #deed_url ⇒ Object
- #icon_url(size = :normal) ⇒ Object
-
#initialize(type, jurisdiction, version) ⇒ LicenseInfo
constructor
A new instance of LicenseInfo.
- #language ⇒ Object
- #translated_title ⇒ Object
- #translated_type ⇒ Object
Constructor Details
#initialize(type, jurisdiction, version) ⇒ LicenseInfo
Returns a new instance of LicenseInfo.
19 20 21 |
# File 'lib/creative_commons_rails/license_info.rb', line 19 def initialize(type, jurisdiction, version) @type, @jurisdiction, @version = type, jurisdiction, version end |
Instance Attribute Details
#jurisdiction ⇒ Object
Returns the value of attribute jurisdiction.
5 6 7 |
# File 'lib/creative_commons_rails/license_info.rb', line 5 def jurisdiction @jurisdiction end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/creative_commons_rails/license_info.rb', line 5 def type @type end |
#version ⇒ Object
Returns the value of attribute version.
5 6 7 |
# File 'lib/creative_commons_rails/license_info.rb', line 5 def version @version end |
Class Method Details
.find(attributes = {}) ⇒ Object
ensure the license exists in the license index
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/creative_commons_rails/license_info.rb', line 8 def self.find(attributes = {}) index = license_index [:jurisdiction, :version, :type].each do |key| raise "You must specify the #{attr} to find a licence" if attributes[key].nil? index = index[attributes[key].to_s] raise "Unknown license #{key}: #{attributes[key]}" if index.nil? || !index end LicenseInfo.new(attributes[:type],attributes[:jurisdiction],attributes[:version]) end |
.license_index ⇒ Object
44 45 46 47 |
# File 'lib/creative_commons_rails/license_info.rb', line 44 def self.license_index gem_root = Gem::Specification.find_by_name("creative_commons_rails").gem_dir @index ||= YAML.load_file("#{gem_root}/config/license_list.yaml") end |
Instance Method Details
#deed_url ⇒ Object
23 24 25 |
# File 'lib/creative_commons_rails/license_info.rb', line 23 def deed_url "http://creativecommons.org/licenses/#{type}/#{version}/#{jurisdiction}/deed.#{language}" end |
#icon_url(size = :normal) ⇒ Object
27 28 29 |
# File 'lib/creative_commons_rails/license_info.rb', line 27 def icon_url(size = :normal) "http://i.creativecommons.org/l/#{type}/#{version}/#{size == :compact ? '80x15' : '88x31'}.png" end |
#language ⇒ Object
39 40 41 |
# File 'lib/creative_commons_rails/license_info.rb', line 39 def language I18n.locale end |
#translated_title ⇒ Object
31 32 33 |
# File 'lib/creative_commons_rails/license_info.rb', line 31 def translated_title I18n.t :license_title, license_type: translated_type end |
#translated_type ⇒ Object
35 36 37 |
# File 'lib/creative_commons_rails/license_info.rb', line 35 def translated_type I18n.t "license_type_#{type}", version: version, jurisdiction: I18n.t(jurisdiction) end |