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
- .available_jurisdictions ⇒ Object
- .available_types(jurisdiction) ⇒ Object
- .available_versions(jurisdiction, type) ⇒ Object
-
.find(attributes = {}) ⇒ Object
ensure the license exists in the license index.
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.
31 32 33 |
# File 'lib/creative_commons_rails/license_info.rb', line 31 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
.available_jurisdictions ⇒ Object
19 20 21 |
# File 'lib/creative_commons_rails/license_info.rb', line 19 def self.available_jurisdictions license_index.keys end |
.available_types(jurisdiction) ⇒ Object
23 24 25 |
# File 'lib/creative_commons_rails/license_info.rb', line 23 def self.available_types(jurisdiction) license_index[jurisdiction.to_s].keys end |
.available_versions(jurisdiction, type) ⇒ Object
27 28 29 |
# File 'lib/creative_commons_rails/license_info.rb', line 27 def self.available_versions(jurisdiction, type) license_index[jurisdiction].select{|k,v| v[type]}.keys end |
.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 |
Instance Method Details
#deed_url ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/creative_commons_rails/license_info.rb', line 35 def deed_url if jurisdiction == "unported" "http://creativecommons.org/licenses/#{type}/#{version}/deed.#{language}" else "http://creativecommons.org/licenses/#{type}/#{version}/#{jurisdiction}/deed.#{language}" end end |
#icon_url(size = :normal) ⇒ Object
43 44 45 |
# File 'lib/creative_commons_rails/license_info.rb', line 43 def icon_url(size = :normal) "http://i.creativecommons.org/l/#{type}/#{version}/#{size == :compact ? '80x15' : '88x31'}.png" end |
#language ⇒ Object
55 56 57 |
# File 'lib/creative_commons_rails/license_info.rb', line 55 def language I18n.locale end |
#translated_title ⇒ Object
47 48 49 |
# File 'lib/creative_commons_rails/license_info.rb', line 47 def translated_title I18n.t :license_title, license_type: translated_type end |
#translated_type ⇒ Object
51 52 53 |
# File 'lib/creative_commons_rails/license_info.rb', line 51 def translated_type I18n.t "license_type_#{type}", version: version, jurisdiction: I18n.t(jurisdiction) end |