class Filmrolls::Metadata::Parser
Constants
- LICENSES
Public Class Methods
load(io)
click to toggle source
# File lib/filmrolls/metadata.rb 6 def self.load(io) 7 doc = YAML.load(io) 8 # Data validation, sort of 9 raise 'YAML input missing `author` key' unless doc.key?('author') 10 raise 'YAML input missing `author.name` key' unless doc['author'].key?('name') 11 raise "YAML input has invalid license `#{doc['license']}`" unless is_valid_license(doc['license']) 12 # Output construction 13 { 14 author: doc['author']['name'], 15 copyright: get_copyright(doc['author']['name'], doc['license']), 16 author_url: doc['license'].nil? ? nil : doc['author']['url'], 17 license_url: get_license_url(doc['license']), 18 marked: !is_public_domain(doc['license']), 19 usage_terms: get_usage_terms(doc['author']['name'], doc['license']) 20 }.delete_if { |k, v| v.nil? } 21 end
Private Class Methods
get_copyright(author, license)
click to toggle source
# File lib/filmrolls/metadata.rb 34 def get_copyright(author, license) 35 is_public_domain(license) ? 36 "© #{author}, %{year}. No rights reserved." : 37 license.nil? ? 38 "© #{author}, %{year}. All rights reserved." : 39 "© #{author}, %{year}. Some rights reserved." 40 end
get_license_url(license)
click to toggle source
# File lib/filmrolls/metadata.rb 42 def get_license_url(license) 43 LICENSES[license.to_sym][:url] unless license.nil? 44 end
get_usage_terms(author, license)
click to toggle source
# File lib/filmrolls/metadata.rb 46 def get_usage_terms(author, license) 47 if is_public_domain(license) 48 [ "To the extent possible under law, #{author} has waived all", 49 'copyright and related or neighboring rights to this work.' ].join(' ') 50 elsif not license.nil? 51 name = LICENSES[license.to_sym][:name] 52 url = LICENSES[license.to_sym][:url] 53 [ "This work is licensed under the Creative Commons #{name} 4.0 International License.", 54 "To view a copy of this license, visit #{url} or send a letter to Creative Commons,", 55 '171 Second Street, Suite 300, San Francisco, California, 94105, USA.' ].join(' ') 56 end 57 end
is_public_domain(license)
click to toggle source
# File lib/filmrolls/metadata.rb 30 def is_public_domain(license) 31 license == 'cc0' 32 end
is_valid_license(license)
click to toggle source
# File lib/filmrolls/metadata.rb 26 def is_valid_license(license) 27 license.nil? or LICENSES.key?(license.to_sym) 28 end