Class: CreativeCommonsRails::LicenseInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/creative_commons_rails/license_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#jurisdictionObject

Returns the value of attribute jurisdiction.



5
6
7
# File 'lib/creative_commons_rails/license_info.rb', line 5

def jurisdiction
  @jurisdiction
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/creative_commons_rails/license_info.rb', line 5

def type
  @type
end

#versionObject

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_jurisdictionsObject



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_urlObject



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

#languageObject



55
56
57
# File 'lib/creative_commons_rails/license_info.rb', line 55

def language
  I18n.locale
end

#translated_titleObject



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_typeObject



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