Class: Mead::Identifier
- Inherits:
-
Object
- Object
- Mead::Identifier
- Includes:
- Validations
- Defined in:
- lib/mead/identifier.rb
Instance Attribute Summary collapse
-
#container ⇒ Object
Returns the value of attribute container.
-
#ead_location ⇒ Object
Returns the value of attribute ead_location.
-
#eadid ⇒ Object
Returns the value of attribute eadid.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#mead ⇒ Object
Returns the value of attribute mead.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#page ⇒ Object
Returns the value of attribute page.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#series ⇒ Object
Returns the value of attribute series.
Instance Method Summary collapse
- #clean_zeros(*args) ⇒ Object
- #container_number_transforms(string) ⇒ Object
- #extract ⇒ Object
-
#initialize(mead, ead_location = nil) ⇒ Identifier
constructor
If a location is given then extraction can take place.
- #parse_ead_location(loc) ⇒ Object
- #parse_mead(*args) ⇒ Object
- #split_container ⇒ Object
- #split_folder ⇒ Object
- #split_page ⇒ Object
- #strip_zeros(num) ⇒ Object
Methods included from Validations
#errors, included, #valid?, #valid_format?, #validate, #validate_format
Constructor Details
#initialize(mead, ead_location = nil) ⇒ Identifier
If a location is given then extraction can take place
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mead/identifier.rb', line 15 def initialize(mead, ead_location=nil) @mead = mead @metadata = nil parse_mead 'eadid', 'series', 'container', 'folder', 'sequence' @ead_location = parse_ead_location(ead_location) split_container split_folder split_page clean_zeros 'series', 'sequence', 'page' self end |
Instance Attribute Details
#container ⇒ Object
Returns the value of attribute container.
4 5 6 |
# File 'lib/mead/identifier.rb', line 4 def container @container end |
#ead_location ⇒ Object
Returns the value of attribute ead_location.
4 5 6 |
# File 'lib/mead/identifier.rb', line 4 def ead_location @ead_location end |
#eadid ⇒ Object
Returns the value of attribute eadid.
4 5 6 |
# File 'lib/mead/identifier.rb', line 4 def eadid @eadid end |
#folder ⇒ Object
Returns the value of attribute folder.
4 5 6 |
# File 'lib/mead/identifier.rb', line 4 def folder @folder end |
#mead ⇒ Object
Returns the value of attribute mead.
4 5 6 |
# File 'lib/mead/identifier.rb', line 4 def mead @mead end |
#metadata ⇒ Object
Returns the value of attribute metadata.
4 5 6 |
# File 'lib/mead/identifier.rb', line 4 def @metadata end |
#page ⇒ Object
Returns the value of attribute page.
4 5 6 |
# File 'lib/mead/identifier.rb', line 4 def page @page end |
#sequence ⇒ Object
Returns the value of attribute sequence.
4 5 6 |
# File 'lib/mead/identifier.rb', line 4 def sequence @sequence end |
#series ⇒ Object
Returns the value of attribute series.
4 5 6 |
# File 'lib/mead/identifier.rb', line 4 def series @series end |
Instance Method Details
#clean_zeros(*args) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/mead/identifier.rb', line 59 def clean_zeros(*args) args.each do |field| instance_var = instance_variable_get('@' + field) if instance_var cleaned_value = strip_zeros(instance_var) instance_variable_set('@' + field, cleaned_value) end end end |
#container_number_transforms(string) ⇒ Object
55 56 57 |
# File 'lib/mead/identifier.rb', line 55 def container_number_transforms(string) string.gsub('_','.').gsub('~', '-').gsub(/^0*/,'') end |
#extract ⇒ Object
97 98 99 100 |
# File 'lib/mead/identifier.rb', line 97 def extract @metadata = Mead::Extractor.new(self).extract self end |
#parse_ead_location(loc) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mead/identifier.rb', line 81 def parse_ead_location(loc) return nil if loc.nil? if loc if loc.is_a? File loc.rewind if loc.eof? @ead_location = loc elsif loc.include?('http://') if loc.include?(@eadid) @ead_location = loc else @ead_location = File.join(loc, @eadid + '.xml') end end end end |
#parse_mead(*args) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/mead/identifier.rb', line 27 def parse_mead(*args) parts = @mead.split('-') args.each_with_index do |field, i| instance_variable_set('@' + field, parts[i]) end end |
#split_container ⇒ Object
34 35 36 37 38 |
# File 'lib/mead/identifier.rb', line 34 def split_container type = CONTAINER_MAPPING[ @container[0,2] ] number = strip_zeros(container_number_transforms(@container[2,10])) @container = {:type=> type, :number=> number} end |
#split_folder ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mead/identifier.rb', line 40 def split_folder if CONTAINER_MAPPING.keys.include?(@folder[0,2]) type = CONTAINER_MAPPING[ @folder[0,2] ] number = strip_zeros(container_number_transforms(@folder[2,10])) else type = 'folder' number = strip_zeros(container_number_transforms(@folder)) end if number.nil? or (number and number.empty?) @folder = nil else @folder = {:type=> type, :number=> number} end end |
#split_page ⇒ Object
77 78 79 |
# File 'lib/mead/identifier.rb', line 77 def split_page @sequence, @page = sequence.split('_') end |
#strip_zeros(num) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/mead/identifier.rb', line 69 def strip_zeros(num) if num == '000' '0' else num.sub(/^0+/,'') end end |