Class: MARC::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/enhanced_marc/record.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRecord

Creates a new MARC::Record using MARC::Leader to work with the leader, rather than a string



8
9
10
11
12
# File 'lib/enhanced_marc/record.rb', line 8

def initialize
  @fields = FieldMap.new
  # leader is 24 bytes
  @leader = Leader.new(' ' * 24) 
end

Instance Attribute Details

#record_typeObject (readonly)

Returns the value of attribute record_type.



4
5
6
# File 'lib/enhanced_marc/record.rb', line 4

def record_type
  @record_type
end

Class Method Details

.new_from_record(record) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/enhanced_marc/record.rb', line 25

def self.new_from_record(record)
  leader = Leader.new(record.leader)
  typed_record = case leader.get_type
    when 'BKS' then MARC::BookRecord.new_from_record(record)
    when 'SER' then MARC::SerialRecord.new_from_record(record)
    when 'VIS' then MARC::VisualRecord.new_from_record(record)
    when 'MIX' then MARC::MixedRecord.new_from_record(record)                
    when 'MAP' then MARC::MapRecord.new_from_record(record)                
    when 'SCO' then MARC::ScoreRecord.new_from_record(record)                
    when 'REC' then MARC::SoundRecord.new_from_record(record)                
    when 'COM' then MARC::ComputerRecord.new_from_record(record)                
  end
  typed_record.fields.reindex
  typed_record
end

Instance Method Details

#bibliographic_levelObject



53
54
55
# File 'lib/enhanced_marc/record.rb', line 53

def bibliographic_level
  @leader.get_blvl
end

#composition_form(human_readable = false) ⇒ Object



50
51
# File 'lib/enhanced_marc/record.rb', line 50

def composition_form(human_readable=false)
end

#contains_type?(record_type) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
# File 'lib/enhanced_marc/record.rb', line 14

def contains_type?(record_type)
  type_map = {"BKS"=>/[at]{1}/, "COM"=>"m", "MAP"=>/[ef]{1}/,"MIX"=>"p", "SCO"=>/[cd]{1}/, "REC"=>/[ij]{1}/, "SER"=>"s", "VIS"=>/[gkor]{1}/}
  matching_fields = []
  @fields.each_by_tag('006').each { | fxd_fld |
    matching_fields << fxd_fld if fxd_fld.value[0,1].match(type_map[record_type])
  
  }
  return nil if matching_fields.empty?
  return matching_fields
end

#created_onObject



66
67
68
69
70
71
72
# File 'lib/enhanced_marc/record.rb', line 66

def created_on
  unless self['008'].value[0,6] == (' '*6)
    return Date.parse(self['008'].value[0,2]+'-'+self['008'].value[2,2]+'-'+self['008'].value[4,2], false)
  else
    return Date.today
  end
end

#get_datesObject



62
63
64
# File 'lib/enhanced_marc/record.rb', line 62

def get_dates

end

#inspect_fixed_fieldsObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/enhanced_marc/record.rb', line 74

def inspect_fixed_fields
  type_map = {/[at]{1}/=>BookType,'m'=>ComputerType,/[ef]{1}/=>MapType,
    'p'=>MixedType,/[cd]{1}/=>ScoreType,/[ij]{1}/=>SoundType,'s'=>SerialType,
    /[gkor]{1}/=>VisualType}
  @fields.each_by_tag('006').each { | fxd_fld |    
    type_map.each_key { | key |
      if fxd_fld.value[0,1].match(key)
        self.extend type_map[key]
      end
    }
  }
end

#is_archival?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/enhanced_marc/record.rb', line 45

def is_archival?
  return @leader.is_archival?
end

#languagesObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/enhanced_marc/record.rb', line 87

def languages
  languages = []
  unless self['008'].value[35,3].empty?
    language = Locale::Info.get_language(self['008'].value[35,3])
    languages << language if language
  end
  @fields.each_by_tag("041") do | oh_four_one |
    langs = oh_four_one.find_all { |sub| sub.code == 'a'}
    langs.each do | lang |
      i = 0
      while (i + 3) <= lang.value.length
        language = Locale::Info.get_language(lang.value[i,3])
        languages << language if language
        i += 3
      end
    end
  end
  languages.uniq
end

#publication_countryObject



57
58
59
60
# File 'lib/enhanced_marc/record.rb', line 57

def publication_country
  return self['008'].value[15,3].strip unless self['008'].value[15,3] == '  '
  return false
end

#to_typed_recordObject



41
42
43
# File 'lib/enhanced_marc/record.rb', line 41

def to_typed_record
  return self.new_from_record(self)
end