Sha256: a52cf249d88e96a30f06fbd19eac2fbb8cc80ca957934d2def4f735f49313c74

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

module MARC

  #edit is a wrapper method to loop until done
  class Record


    def edit
      puts "Subfield Editing"
      puts "To denote which subfield you want to edit put it in the form of 245a.\nIn the case of repeating fields or subfields you will be prompted\nto choose the one you wish to edit. "
      continue = true
      while continue
	      fs = ask("What field and subfield would you like to edit (in form 245a) or quit?\n>   "){|q| q.readline = true}
        if fs == 'q' || fs == 'quit'
          continue = false
        next
        end
        if !(fs =~/\d\d\d\w/ )
          puts "That's not a valid value"
          next
        end
        self.change_subfield(fs)
      end
    end

    #edit_subfield is passed to a MARC::Record object and give a subfield
    def change_subfield(fs)
      field_subfield = subfield_parse(fs)
      field = field_subfield[0]
      subfield = field_subfield[1]

      fields = self.find_all {|f| f.tag == field}
      subfields = []
      for field in fields
	      subfields << field.find_all {|s| s.code == subfield}
      end
      subfields.flatten!
      if subfields.length > 1
        i = 0
        for subfield in subfields
	        puts "#{i}\t#{subfield}"
          i += 1
        end
	      num_to_change = ask("Which subfield do you want to change?"){|q| q.readline = true}
	      subfield_to_change = subfields[num_to_change.to_i]
      elsif subfields.length == 1
        subfield_to_change = subfields[0]
      elsif subfields.empty?
        puts "No such subfield!"
	      return nil
      end
      

      puts self; puts

      print "Currently:\t"
      puts subfield_to_change.value 
      edit = ask("Your edit:\t"){|q| q.readline = true}
      subfield_to_change.value = edit
      puts; puts self; puts

    end

    #subfield_parse method for getting from '245a' to ['245','a']
    def subfield_parse(combined)
      field_subfield = []
      field_subfield << combined[0, 3]
      field_subfield << combined[3,1]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zcc-0.0.3 lib/zcc/subfieldeditor.rb
zcc-0.1.0 lib/zcc/subfieldeditor.rb