Class: Mods::Record
- Inherits:
-
Object
- Object
- Mods::Record
- Defined in:
- lib/mods/record.rb,
lib/mods/nom_terminology.rb
Constant Summary collapse
- NS_HASH =
{'m' => MODS_NS_V3}
- ATTRIBUTES =
['id', 'version']
Instance Attribute Summary collapse
-
#mods_ng_xml ⇒ Object
readonly
Returns the value of attribute mods_ng_xml.
-
#title_delimiter ⇒ Object
string to use when combining a title and subtitle, e.g.
Instance Method Summary collapse
-
#alternative_titles ⇒ Object
Array of Strings, each containing the text contents of <mods><titleInfo @type=“alternative”><title> elements.
-
#corporate_names ⇒ Object
use the displayForm of a corporate name if present otherwise, return all nameParts concatenated together.
-
#from_file(url, ns_aware = true) ⇒ Object
Convenience method to call Mods::Reader.new.from_file.
-
#from_nk_node(node, ns_aware = true) ⇒ Object
convenience method to call Mods::Reader.new.from_nk_node and to nom.
-
#from_str(str, ns_aware = true) ⇒ Object
convenience method to call Mods::Reader.new.from_str and to nom.
-
#from_url(url, ns_aware = true) ⇒ Object
Convenience method to call Mods::Reader.new.from_url and to nom.
-
#full_titles ⇒ Object
Array of Strings, each containing the text contents of <mods><titleInfo> <nonSort> + ‘ ’ + <title> + (delim) + <subTitle> elements.
-
#initialize(title_delimiter = Mods::TitleInfo::DEFAULT_TITLE_DELIM) ⇒ Record
constructor
A new instance of Record.
-
#languages ⇒ Object
Translates iso-639 language codes, and leaves everything else alone.
- #method_missing(method_name, *args) ⇒ Object
-
#personal_names ⇒ Object
Array of Strings, each containing the computed display value of a personal name (see nom_terminology for algorithm).
-
#personal_names_w_dates ⇒ Object
Array of Strings, each containing the computed display value of a personal name (see nom_terminology for algorithm).
-
#set_terminology_no_ns(mods_ng_xml) ⇒ Object
set the NOM terminology; do NOT use namespaces NOTES: 1.
-
#set_terminology_ns(mods_ng_xml) ⇒ Object
set the NOM terminology; WITH namespaces NOTES: 1.
-
#short_titles ⇒ Object
Array of Strings, each containing the text contents of <mods><titleInfo> <nonSort> + ‘ ’ + <title> elements but not including any titleInfo elements with type=“alternative”.
-
#sort_title ⇒ Object
String containing sortable title for this mods record.
-
#term_value(messages, sep = ' ') ⇒ String
get the value for the terms, as a String.
-
#term_values(messages) ⇒ Array<String>
get the values for the terms, as an Array.
Constructor Details
#initialize(title_delimiter = Mods::TitleInfo::DEFAULT_TITLE_DELIM) ⇒ Record
Returns a new instance of Record.
20 21 22 |
# File 'lib/mods/record.rb', line 20 def initialize(title_delimiter = Mods::TitleInfo::DEFAULT_TITLE_DELIM) @title_delimiter = title_delimiter end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
214 215 216 217 218 219 220 |
# File 'lib/mods/record.rb', line 214 def method_missing method_name, *args if mods_ng_xml.respond_to?(method_name) mods_ng_xml.send(method_name, *args) else super.method_missing(method_name, *args) end end |
Instance Attribute Details
#mods_ng_xml ⇒ Object (readonly)
Returns the value of attribute mods_ng_xml.
7 8 9 |
# File 'lib/mods/record.rb', line 7 def mods_ng_xml @mods_ng_xml end |
#title_delimiter ⇒ Object
string to use when combining a title and subtitle, e.g.
for title "MODS" and subtitle "Metadata Odious Delimited Stuff" and delimiter " : "
we get "MODS : Metadata Odious Delimited Stuff"
11 12 13 |
# File 'lib/mods/record.rb', line 11 def title_delimiter @title_delimiter end |
Instance Method Details
#alternative_titles ⇒ Object
Returns Array of Strings, each containing the text contents of <mods><titleInfo @type=“alternative”><title> elements.
151 152 153 |
# File 'lib/mods/record.rb', line 151 def alternative_titles @mods_ng_xml.title_info.alternative_title.map { |n| n } end |
#corporate_names ⇒ Object
use the displayForm of a corporate name if present
otherwise, return all nameParts concatenated together
175 176 177 |
# File 'lib/mods/record.rb', line 175 def corporate_names @mods_ng_xml.corporate_name.map { |n| n.display_value } end |
#from_file(url, ns_aware = true) ⇒ Object
Convenience method to call Mods::Reader.new.from_file. Returns a new instance of Mods::Record instantiated with the content from the given file.
62 63 64 65 66 67 68 69 70 |
# File 'lib/mods/record.rb', line 62 def from_file(url, ns_aware = true) @mods_ng_xml = Mods::Reader.new(ns_aware).from_file(url) if ns_aware set_terminology_ns(@mods_ng_xml) else set_terminology_no_ns(@mods_ng_xml) end return self end |
#from_nk_node(node, ns_aware = true) ⇒ Object
convenience method to call Mods::Reader.new.from_nk_node and to nom
76 77 78 79 80 81 82 83 84 |
# File 'lib/mods/record.rb', line 76 def from_nk_node(node, ns_aware = true) @mods_ng_xml = Mods::Reader.new(ns_aware).from_nk_node(node) if ns_aware set_terminology_ns(@mods_ng_xml) else set_terminology_no_ns(@mods_ng_xml) end return self end |
#from_str(str, ns_aware = true) ⇒ Object
convenience method to call Mods::Reader.new.from_str and to nom
28 29 30 31 32 33 34 35 36 |
# File 'lib/mods/record.rb', line 28 def from_str(str, ns_aware = true) @mods_ng_xml = Mods::Reader.new(ns_aware).from_str(str) if ns_aware set_terminology_ns(@mods_ng_xml) else set_terminology_no_ns(@mods_ng_xml) end return self end |
#from_url(url, ns_aware = true) ⇒ Object
Convenience method to call Mods::Reader.new.from_url and to nom. Returns a new instance of Mods::Record instantiated with the content from the given URL.
45 46 47 48 49 50 51 52 53 |
# File 'lib/mods/record.rb', line 45 def from_url(url, ns_aware = true) @mods_ng_xml = Mods::Reader.new(ns_aware).from_url(url) if ns_aware set_terminology_ns(@mods_ng_xml) else set_terminology_no_ns(@mods_ng_xml) end return self end |
#full_titles ⇒ Object
Returns Array of Strings, each containing the text contents of <mods><titleInfo> <nonSort> + ‘ ’ + <title> + (delim) + <subTitle> elements.
146 147 148 |
# File 'lib/mods/record.rb', line 146 def full_titles @mods_ng_xml.title_info.full_title.map { |n| n } end |
#languages ⇒ Object
Translates iso-639 language codes, and leaves everything else alone.
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/mods/record.rb', line 181 def languages result = [] @mods_ng_xml.language.each { |n| # get languageTerm codes and add their translations to the result n.code_term.each { |ct| if ct..match(/^iso639/) begin vals = ct.text.split(/[,|\ ]/).reject {|x| x.strip.length == 0 } vals.each do |v| result << ISO_639.find(v.strip).english_name end rescue => e p "Couldn't find english name for #{ct.text}" result << ct.text end else result << ct.text end } # add languageTerm text values n.text_term.each { |tt| val = tt.text.strip result << val if val.length > 0 } # add language values that aren't in languageTerm subelement if n.languageTerm.size == 0 result << n.text end } result.uniq end |
#personal_names ⇒ Object
Returns Array of Strings, each containing the computed display value of a personal name (see nom_terminology for algorithm).
162 163 164 |
# File 'lib/mods/record.rb', line 162 def personal_names @mods_ng_xml.personal_name.map { |n| n.display_value } end |
#personal_names_w_dates ⇒ Object
Returns Array of Strings, each containing the computed display value of a personal name (see nom_terminology for algorithm).
168 169 170 |
# File 'lib/mods/record.rb', line 168 def personal_names_w_dates @mods_ng_xml.personal_name.map { |n| n.display_value_w_date } end |
#set_terminology_no_ns(mods_ng_xml) ⇒ Object
set the NOM terminology; do NOT use namespaces NOTES:
-
certain words, such as ‘type’ ‘name’ ‘description’ are reserved words in jruby or nokogiri
when the terminology would use these words, a suffix of '_at' is added if it is an attribute,
(e.g. 'type_at' for @type) and a suffix of '_el' is added if it is an element.
-
the underscore prefix variant terms are a way of making subterms for a node available
to any instance of said node and are not intended to be used externally
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 |
# File 'lib/mods/nom_terminology.rb', line 646 def set_terminology_no_ns(mods_ng_xml) mods_ng_xml.set_terminology() do |t| # FIXME: may want to deal with camelcase vs. underscore in method_missing # ABSTRACT ------------------------------------------------------------------------------- t.abstract :path => '/mods/abstract' t._abstract :path => '//abstract' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # ACCESS_CONDITION ----------------------------------------------------------------------- t.accessCondition :path => '/mods/accessCondition' t._accessCondition :path => '//accessCondition' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # CLASSIFICATION ------------------------------------------------------------------------- t.classification :path => '/mods/classification' t._classification :path => '//classification' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.edition :path => '@edition', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # EXTENSION ------------------------------------------------------------------------------ t.extension :path => '/mods/extension' t._extension :path => '//extension' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } end # GENRE ---------------------------------------------------------------------------------- t.genre :path => '/mods/genre' t._genre :path => '//genre' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } n.usage :path => '@usage', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # IDENTIIER ------------------------------------------------------------------------------ t.identifier :path => '/mods/identifier' t._identifier :path => '//identifier' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.invalid :path => '@invalid', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # LANGUAGE ------------------------------------------------------------------------------- t.language :path => '/mods/language' t._language :path => '//language' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.languageTerm :path => 'languageTerm' n.code_term :path => 'languageTerm[@type="code"]' n.text_term :path => 'languageTerm[@type="text"]' n.scriptTerm :path => 'scriptTerm' end t._languageTerm :path => '//languageTerm' do |lt| lt.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| lt.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # t.language # LOCATION ------------------------------------------------------------------------------- t.location :path => '/mods/location' t._location :path => '//location' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.physicalLocation :path => 'physicalLocation' do |e| e.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| e.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.shelfLocator :path => 'shelfLocator' n.url :path => 'url' do |e| e.dateLastAccessed :path => '@dateLastAccessed', :accessor => lambda { |a| a.text } e.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } e.note :path => '@note', :accessor => lambda { |a| a.text } e.access :path => '@access', :accessor => lambda { |a| a.text } e.usage :path => '@usage', :accessor => lambda { |a| a.text } end n.holdingSimple :path => 'holdingSimple' n.holdingExternal :path => 'holdingExternal' end # t.location # NAME ------------------------------------------------------------------------------------ t.plain_name :path => '/mods/name' t._plain_name :path => '//name' do |n| Mods::Name::ATTRIBUTES.each { |attr_name| if attr_name != 'type' n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } else n.type_at :path => "@#{attr_name}", :accessor => lambda { |a| a.text } end } # elements n.namePart :path => 'namePart' do |np| np.type_at :path => '@type', :accessor => lambda { |a| a.text } end n.family_name :path => 'namePart[@type="family"]' n.given_name :path => 'namePart[@type="given"]' n.termsOfAddress :path => 'namePart[@type="termsOfAddress"]' n.date :path => 'namePart[@type="date"]' n.displayForm :path => 'displayForm' n.affiliation :path => 'affiliation' n.description_el :path => 'description' # description is used by Nokogiri n.role :path => 'role' do |r| r.roleTerm :path => 'roleTerm' do |rt| rt.type_at :path => "@type", :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| rt.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # convenience method r. :path => '.', :accessor => lambda { |role_node| a = nil role_node.roleTerm.each { |role_t| # role_t.authority will be [] if it is missing from an earlier roleTerm if role_t. && (!a || a.size == 0) a = role_t. end } a } # convenience method r.code :path => '.', :accessor => lambda { |role_node| c = nil role_node.roleTerm.each { |role_t| if role_t.type_at == 'code' c ||= role_t.text end } c } # convenience method r.value :path => '.', :accessor => lambda { |role_node| val = nil role_node.roleTerm.each { |role_t| if role_t.type_at == 'text' val ||= role_t.text end } # FIXME: this is broken if there are multiple role codes and some of them are not marcrelator if !val && role_node.code && role_node..first =~ /marcrelator/ val = MARC_RELATOR[role_node.code.first] end val } end # role node # name convenience method # uses the displayForm of a name if present # if no displayForm, try to make a string from family, given and terms of address # otherwise, return all non-date nameParts concatenated together n.display_value :path => '.', :single => true, :accessor => lambda {|name_node| dv = '' if name_node.displayForm && name_node.displayForm.text.size > 0 dv = name_node.displayForm.text end if dv.empty? if name_node.type_at == 'personal' if name_node.family_name.size > 0 dv = name_node.given_name.size > 0 ? "#{name_node.family_name.text}, #{name_node.given_name.text}" : name_node.family_name.text elsif name_node.given_name.size > 0 dv = name_node.given_name.text end if !dv.empty? first = true name_node.namePart.each { |np| if np.type_at == 'termsOfAddress' && !np.text.empty? if first dv = dv + " " + np.text first = false else dv = dv + ", " + np.text end end } else # no family or given name dv = name_node.namePart.select {|np| np.type_at != 'date' && !np.text.empty?}.join(" ") end else # not a personal name dv = name_node.namePart.select {|np| np.type_at != 'date' && !np.text.empty?}.join(" ") end end dv.strip.empty? ? nil : dv.strip } # name convenience method n.display_value_w_date :path => '.', :single => true, :accessor => lambda {|name_node| dv = '' + name_node.display_value name_node.namePart.each { |np| if np.type_at == 'date' && !np.text.empty? && !dv.end_with?(np.text) dv = dv + ", #{np.text}" end } if dv.start_with?(', ') dv.sub(', ', '') end dv.strip.empty? ? nil : dv.strip } end # t._plain_name t.personal_name :path => '/mods/name[@type="personal"]' t._personal_name :path => '//name[@type="personal"]' t.corporate_name :path => '/mods/name[@type="corporate"]' t._corporate_name :path => '//name[@type="corporate"]' t.conference_name :path => '/mods/name[@type="conference"]' t._conference_name :path => '//name[@type="conference"]' # NOTE --------------------------------------------------------------------------------- t.note :path => '/mods/note' t._note :path => '//note' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.id_at :path => '@ID', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # ORIGIN_INFO -------------------------------------------------------------------------- t.origin_info :path => '/mods/originInfo' t._origin_info :path => '//originInfo' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.place :path => 'place' do |e| e.placeTerm :path => 'placeTerm' do |ee| ee.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| ee.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end end n.publisher :path => 'publisher' Mods::OriginInfo::DATE_ELEMENTS.each { |date_el| n.send date_el, :path => "#{date_el}" do |d| Mods::DATE_ATTRIBS.each { |attr_name| d.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } if date_el == 'dateOther' d.type_at :path => '@type', :accessor => lambda { |a| a.text } end end } n.edition :path => 'edition' n.issuance :path => 'issuance' n.frequency :path => 'frequency' do |f| Mods::AUTHORITY_ATTRIBS.each { |attr_name| f.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end end # t.origin_info # PART ----------------------------------------------------------------------------------- t.part :path => '/mods/part' t._part :path => '//part' do |n| # attributes n.id_at :path => '@ID', :accessor => lambda { |a| a.text } n.order :path => '@order', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.detail :path => 'detail' do |e| # attributes e.level :path => '@level', :accessor => lambda { |a| a.text } e.type_at :path => '@type', :accessor => lambda { |a| a.text } # elements e.number :path => 'number' e. :path => 'caption' e.title :path => 'title' end n.extent :path => 'extent' do |e| # TODO: extent is ordered in xml schema # attributes e.unit :path => '@unit', :accessor => lambda { |a| a.text } # elements e.start :path => 'start' e.end :path => 'end' e.total :path => 'total' e.list :path => 'list' end n.date :path => 'date' do |e| Mods::DATE_ATTRIBS.reject { |a| a == 'keyDate' }.each { |attr_name| e.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.text_el :path => 'text' do |e| e.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } e.type_at :path => '@type', :accessor => lambda { |a| a.text } end end # t._part # PHYSICAL_DESCRIPTION ------------------------------------------------------------------- t.physical_description :path => '/mods/physicalDescription' t._physical_description :path => '//physicalDescription' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.digitalOrigin :path => 'digitalOrigin' n.extent :path => 'extent' n.form :path => 'form' do |f| f.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| f.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.internetMediaType :path => 'internetMediaType' n.note :path => 'note' do |nn| nn.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } nn.type_at :path => '@type', :accessor => lambda { |a| a.text } end n.reformattingQuality :path => 'reformattingQuality' end # RECORD_INFO -------------------------------------------------------------------------- t.record_info :path => '/mods/recordInfo' t._record_info :path => '//recordInfo' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.recordContentSource :path => 'recordContentSource' do |r| Mods::AUTHORITY_ATTRIBS.each { |attr_name| r.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.recordCreationDate :path => 'recordCreationDate' do |r| Mods::DATE_ATTRIBS.each { |attr_name| r.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.recordChangeDate :path => 'recordChangeDate' do |r| Mods::DATE_ATTRIBS.each { |attr_name| r.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.recordIdentifier :path => 'recordIdentifier' do |r| r.source :path => '@source', :accessor => lambda { |a| a.text } end n.recordOrigin :path => 'recordOrigin' n.languageOfCataloging :path => 'languageOfCataloging' do |r| Mods::AUTHORITY_ATTRIBS.each { |attr_name| r.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } r.languageTerm :path => 'languageTerm' r.scriptTerm :path => 'scriptTerm' end n.descriptionStandard :path => 'descriptionStandard' do |r| Mods::AUTHORITY_ATTRIBS.each { |attr_name| r.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end end # t._record_info # RELATED_ITEM------------------------------------------------------------------------- t. :path => '/mods/relatedItem' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.id_at :path => '@ID', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } # elements n.abstract :path => 'abstract' n.accessCondition :path => 'accessCondition' n.classification :path => 'classification' n.extension :path => 'extension' n.genre :path => 'genre' n.identifier :path => 'identifier' n.language :path => 'language' n.location :path => 'location' n.name_el :path => 'name' # Note: 'name' is used by Nokogiri n.personal_name :path => 'name[@type="personal"]' n.corporate_name :path => 'name[@type="corporate"]' n.conference_name :path => 'name[@type="conference"]' n.note :path => 'note' n.originInfo :path => 'originInfo' n.part :path => 'part' n.physicalDescription :path => 'physicalDescription' n.recordInfo :path => 'recordInfo' n.subject :path => 'subject' n.tableOfContents :path => 'tableOfContents' n.targetAudience :path => 'targetAudience' n.titleInfo :path => 'titleInfo' n.typeOfResource :path => 'typeOfResource' end # SUBJECT ----------------------------------------------------------------------------- t.subject :path => '/mods/subject' t._subject :path => '//subject' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.cartographics :path => 'cartographics' do |n1| n1.scale :path => 'scale' n1.projection :path => 'projection' n1.coordinates :path => 'coordinates' Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.each { |elname| n1.send elname, :path => "#{elname}" } end n.geographic :path => 'geographic' do |n1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.genre :path => 'genre' do |n1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.geographicCode :path => 'geographicCode' do |gc| Mods::AUTHORITY_ATTRIBS.each { |attr_name| gc.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # convenience method gc.translated_value :path => '.', :accessor => lambda { |gc_node| code_val ||= gc_node.text xval = nil if code_val case gc_node. when 'marcgac' xval = MARC_GEOGRAPHIC_AREA[code_val] when 'marccountry' xval = MARC_COUNTRY[code_val] end end xval } end n.hierarchicalGeographic :path => 'hierarchicalGeographic' do |n1| Mods::Subject::HIER_GEO_CHILD_ELEMENTS.each { |elname| n1.send elname, :path => "#{elname}" } Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # Note: 'name' is used by Nokogiri n.name_el :path => 'name' do |t1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| t1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.personal_name :path => 'name[@type="personal"]' n.corporate_name :path => 'name[@type="corporate"]' n.conference_name :path => 'name[@type="conference"]' n.occupation :path => 'occupation' do |n1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.temporal :path => 'temporal' do |n1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # date attributes as attributes Mods::DATE_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.titleInfo :path => 'titleInfo' do |t1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| t1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.topic :path => 'topic' do |n1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end end # t.subject # TABLE_OF_CONTENTS --------------------------------------------------------------------- t.tableOfContents :path => '/mods/tableOfContents' t._tableOfContents :path => '//tableOfContents' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.shareable :path => '@shareable', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # TARGET_AUDIENCE ----------------------------------------------------------------------- t.targetAudience :path => '/mods/targetAudience' t._targetAudience :path => '//targetAudience' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # TITLE_INFO ---------------------------------------------------------------------------- t.title_info :path => '/mods/titleInfo' t._title_info :path => '//titleInfo' do |n| Mods::TitleInfo::ATTRIBUTES.each { |attr_name| if attr_name != 'type' n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } else n.type_at :path => "@#{attr_name}", :accessor => lambda { |a| a.text } end } n.title :path => 'title' n.subTitle :path => 'subTitle' n.nonSort :path => 'nonSort' n.partNumber :path => 'partNumber' n.partName :path => 'partName' n.sort_title :path => '.', :accessor => lambda { |node| if node.type_at != "alternative" || (node.type_at == "alternative" && mods_ng_xml.xpath('/mods/titleInfo').size == 1) node.title.text + (!node.subTitle.text.empty? ? "#{@title_delimiter}#{node.subTitle.text}" : "" ) end } n.full_title :path => '.', :accessor => lambda { |node| (!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) + node.title.text + (!node.subTitle.text.empty? ? "#{@title_delimiter}#{node.subTitle.text}" : "" ) } n.short_title :path => '.', :accessor => lambda { |node| if node.type_at != "alternative" (!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) + node.title.text end } n.alternative_title :path => '.', :accessor => lambda { |node| if node.type_at == "alternative" (!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) + node.title.text end } end # t._title_info # TYPE_OF_RESOURCE -------------------------------------------------------------------- t.typeOfResource :path => '/mods/typeOfResource' t._typeOfResource :path => '//typeOfResource' do |n| n.collection :path => '@collection', :accessor => lambda { |a| a.text } n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.manuscript :path => '@manuscript', :accessor => lambda { |a| a.text } n.usage :path => '@usage', :accessor => lambda { |a| a.text } end end # terminology mods_ng_xml.nom! mods_ng_xml end |
#set_terminology_ns(mods_ng_xml) ⇒ Object
set the NOM terminology; WITH namespaces NOTES:
-
certain words, such as ‘type’ ‘name’ ‘description’ are reserved words in jruby or nokogiri
when the terminology would use these words, a suffix of '_at' is added if it is an attribute,
(e.g. 'type_at' for @type) and a suffix of '_el' is added if it is an element.
-
the underscore prefix variant terms are a way of making subterms for a node available
to any instance of said node and are not intended to be used externally
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/mods/nom_terminology.rb', line 30 def set_terminology_ns(mods_ng_xml) mods_ng_xml.set_terminology(:namespaces => { 'm' => Mods::MODS_NS }) do |t| # FIXME: may want to deal with camelcase vs. underscore in method_missing # ABSTRACT ------------------------------------------------------------------------------- t.abstract :path => '/m:mods/m:abstract' t._abstract :path => '//m:abstract' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # ACCESS_CONDITION ----------------------------------------------------------------------- t.accessCondition :path => '/m:mods/m:accessCondition' t._accessCondition :path => '//m:accessCondition' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # CLASSIFICATION ------------------------------------------------------------------------- t.classification :path => '/m:mods/m:classification' t._classification :path => '//m:classification' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.edition :path => '@edition', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # EXTENSION ------------------------------------------------------------------------------ t.extension :path => '/m:mods/m:extension' t._extension :path => '//m:extension' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } end # GENRE ---------------------------------------------------------------------------------- t.genre :path => '/m:mods/m:genre' t._genre :path => '//m:genre' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } n.usage :path => '@usage', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # IDENTIIER ------------------------------------------------------------------------------ t.identifier :path => '/m:mods/m:identifier' t._identifier :path => '//m:identifier' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.invalid :path => '@invalid', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # LANGUAGE ------------------------------------------------------------------------------- t.language :path => '/m:mods/m:language' t._language :path => '//m:language' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.languageTerm :path => 'm:languageTerm' n.code_term :path => 'm:languageTerm[@type="code"]' n.text_term :path => 'm:languageTerm[@type="text"]' n.scriptTerm :path => 'm:scriptTerm' end t._languageTerm :path => '//m:languageTerm' do |lt| lt.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| lt.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # t.language # LOCATION ------------------------------------------------------------------------------- t.location :path => '/m:mods/m:location' t._location :path => '//m:location' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.physicalLocation :path => 'm:physicalLocation' do |e| e.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| e.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.shelfLocator :path => 'm:shelfLocator' n.url :path => 'm:url' do |e| e.dateLastAccessed :path => '@dateLastAccessed', :accessor => lambda { |a| a.text } e.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } e.note :path => '@note', :accessor => lambda { |a| a.text } e.access :path => '@access', :accessor => lambda { |a| a.text } e.usage :path => '@usage', :accessor => lambda { |a| a.text } end n.holdingSimple :path => 'm:holdingSimple' n.holdingExternal :path => 'm:holdingExternal' end # t.location # NAME ------------------------------------------------------------------------------------ t.plain_name :path => '/m:mods/m:name' t._plain_name :path => '//m:name' do |n| Mods::Name::ATTRIBUTES.each { |attr_name| if attr_name != 'type' n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } else n.type_at :path => "@#{attr_name}", :accessor => lambda { |a| a.text } end } # elements n.namePart :path => 'm:namePart' do |np| np.type_at :path => '@type', :accessor => lambda { |a| a.text } end n.family_name :path => 'm:namePart[@type="family"]' n.given_name :path => 'm:namePart[@type="given"]' n.termsOfAddress :path => 'm:namePart[@type="termsOfAddress"]' n.date :path => 'm:namePart[@type="date"]' n.displayForm :path => 'm:displayForm' n.affiliation :path => 'm:affiliation' n.description_el :path => 'm:description' # description is used by Nokogiri n.role :path => 'm:role' do |r| r.roleTerm :path => 'm:roleTerm' do |rt| rt.type_at :path => "@type", :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| rt.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # role convenience method r. :path => '.', :accessor => lambda { |role_node| a = nil role_node.roleTerm.each { |role_t| # role_t.authority will be [] if it is missing from an earlier roleTerm if role_t. && (!a || a.size == 0) a = role_t. end } a } # role convenience method r.code :path => '.', :accessor => lambda { |role_node| c = nil role_node.roleTerm.each { |role_t| if role_t.type_at == 'code' c ||= role_t.text end } c } # role convenience method r.value :path => '.', :accessor => lambda { |role_node| val = nil role_node.roleTerm.each { |role_t| if role_t.type_at == 'text' val ||= role_t.text end } # FIXME: this is broken if there are multiple role codes and some of them are not marcrelator if !val && role_node.code && role_node..first =~ /marcrelator/ val = MARC_RELATOR[role_node.code.first] end val } end # role node # name convenience method # uses the displayForm of a name if present # if no displayForm, try to make a string from family, given and terms of address # otherwise, return all non-date nameParts concatenated together n.display_value :path => '.', :single => true, :accessor => lambda {|name_node| dv = '' if name_node.displayForm && name_node.displayForm.text.size > 0 dv = name_node.displayForm.text end if dv.empty? if name_node.type_at == 'personal' if name_node.family_name.size > 0 dv = name_node.given_name.size > 0 ? "#{name_node.family_name.text}, #{name_node.given_name.text}" : name_node.family_name.text elsif name_node.given_name.size > 0 dv = name_node.given_name.text end if !dv.empty? first = true name_node.namePart.each { |np| if np.type_at == 'termsOfAddress' && !np.text.empty? if first dv = dv + " " + np.text first = false else dv = dv + ", " + np.text end end } else # no family or given name dv = name_node.namePart.select {|np| np.type_at != 'date' && !np.text.empty?}.join(" ") end else # not a personal name dv = name_node.namePart.select {|np| np.type_at != 'date' && !np.text.empty?}.join(" ") end end dv.strip.empty? ? nil : dv.strip } # name convenience method n.display_value_w_date :path => '.', :single => true, :accessor => lambda {|name_node| dv = '' dv = dv + name_node.display_value if name_node.display_value name_node.namePart.each { |np| if np.type_at == 'date' && !np.text.empty? && !dv.end_with?(np.text) dv = dv + ", #{np.text}" end } if dv.start_with?(', ') dv.sub(', ', '') end dv.strip.empty? ? nil : dv.strip } end # t._plain_name t.personal_name :path => '/m:mods/m:name[@type="personal"]' t._personal_name :path => '//m:name[@type="personal"]' t.corporate_name :path => '/m:mods/m:name[@type="corporate"]' t._corporate_name :path => '//m:name[@type="corporate"]' t.conference_name :path => '/m:mods/m:name[@type="conference"]' t._conference_name :path => '//m:name[@type="conference"]' # NOTE --------------------------------------------------------------------------------- t.note :path => '/m:mods/m:note' t._note :path => '//m:note' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.id_at :path => '@ID', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # ORIGIN_INFO -------------------------------------------------------------------------- t.origin_info :path => '/m:mods/m:originInfo' t._origin_info :path => '//m:originInfo' do |n| n.as_object :path => '.', :accessor => lambda { |a| Mods::OriginInfo.new(a) } # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.place :path => 'm:place' do |e| e.placeTerm :path => 'm:placeTerm' do |ee| ee.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| ee.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end end n.publisher :path => 'm:publisher' Mods::OriginInfo::DATE_ELEMENTS.each { |date_el| n.send date_el, :path => "m:#{date_el}" do |d| d.as_object :path => '.', :accessor => lambda { |a| Mods::Date.from_element(a) } Mods::DATE_ATTRIBS.each { |attr_name| d.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } if date_el == 'dateOther' d.type_at :path => '@type', :accessor => lambda { |a| a.text } end end } n.edition :path => 'm:edition' n.issuance :path => 'm:issuance' n.frequency :path => 'm:frequency' do |f| Mods::AUTHORITY_ATTRIBS.each { |attr_name| f.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end end # t.origin_info # PART ----------------------------------------------------------------------------------- t.part :path => '/m:mods/m:part' t._part :path => '//m:part' do |n| # attributes n.id_at :path => '@ID', :accessor => lambda { |a| a.text } n.order :path => '@order', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.detail :path => 'm:detail' do |e| # attributes e.level :path => '@level', :accessor => lambda { |a| a.text } e.type_at :path => '@type', :accessor => lambda { |a| a.text } # elements e.number :path => 'm:number' e. :path => 'm:caption' e.title :path => 'm:title' end n.extent :path => 'm:extent' do |e| # TODO: extent is ordered in xml schema # attributes e.unit :path => '@unit', :accessor => lambda { |a| a.text } # elements e.start :path => 'm:start' e.end :path => 'm:end' e.total :path => 'm:total' e.list :path => 'm:list' end n.date :path => 'm:date' do |e| Mods::DATE_ATTRIBS.reject { |a| a == 'keyDate' }.each { |attr_name| e.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.text_el :path => 'm:text' do |e| e.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } e.type_at :path => '@type', :accessor => lambda { |a| a.text } end end # t._part # PHYSICAL_DESCRIPTION ------------------------------------------------------------------- t.physical_description :path => '/m:mods/m:physicalDescription' t._physical_description :path => '//m:physicalDescription' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.digitalOrigin :path => 'm:digitalOrigin' n.extent :path => 'm:extent' n.form :path => 'm:form' do |f| f.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| f.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.internetMediaType :path => 'm:internetMediaType' n.note :path => 'm:note' do |nn| nn.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } nn.type_at :path => '@type', :accessor => lambda { |a| a.text } end n.reformattingQuality :path => 'm:reformattingQuality' end # RECORD_INFO -------------------------------------------------------------------------- t.record_info :path => '/m:mods/m:recordInfo' t._record_info :path => '//m:recordInfo' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.recordContentSource :path => 'm:recordContentSource' do |r| Mods::AUTHORITY_ATTRIBS.each { |attr_name| r.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.recordCreationDate :path => 'm:recordCreationDate' do |r| Mods::DATE_ATTRIBS.each { |attr_name| r.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.recordChangeDate :path => 'm:recordChangeDate' do |r| Mods::DATE_ATTRIBS.each { |attr_name| r.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.recordIdentifier :path => 'm:recordIdentifier' do |r| r.source :path => '@source', :accessor => lambda { |a| a.text } end n.recordOrigin :path => 'm:recordOrigin' n.languageOfCataloging :path => 'm:languageOfCataloging' do |r| Mods::AUTHORITY_ATTRIBS.each { |attr_name| r.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } r.languageTerm :path => 'm:languageTerm' r.scriptTerm :path => 'm:scriptTerm' end n.descriptionStandard :path => 'm:descriptionStandard' do |r| Mods::AUTHORITY_ATTRIBS.each { |attr_name| r.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end end # t._record_info # RELATED_ITEM------------------------------------------------------------------------- t. :path => '/m:mods/m:relatedItem' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.id_at :path => '@ID', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } # elements n.abstract :path => 'abstract' n.accessCondition :path => 'm:accessCondition' n.classification :path => 'm:classification' n.extension :path => 'm:extension' n.genre :path => 'm:genre' n.identifier :path => 'm:identifier' n.language :path => 'm:language' n.location :path => 'm:location' n.name_el :path => 'm:name' # Note: 'name' is used by Nokogiri n.personal_name :path => 'm:name[@type="personal"]' n.corporate_name :path => 'm:name[@type="corporate"]' n.conference_name :path => 'm:name[@type="conference"]' n.note :path => 'm:note' n.originInfo :path => 'm:originInfo' n.part :path => 'm:part' n.physicalDescription :path => 'm:physicalDescription' n.recordInfo :path => 'm:recordInfo' n.subject :path => 'm:subject' n.tableOfContents :path => 'm:tableOfContents' n.targetAudience :path => 'm:targetAudience' n.titleInfo :path => 'm:titleInfo' n.typeOfResource :path => 'm:typeOfResource' end # SUBJECT ----------------------------------------------------------------------------- t.subject :path => '/m:mods/m:subject' t._subject :path => '//m:subject' do |n| # attributes n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # child elements n.cartographics :path => 'm:cartographics' do |n1| n1.scale :path => 'm:scale' n1.projection :path => 'm:projection' n1.coordinates :path => 'm:coordinates' Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.each { |elname| n1.send elname, :path => "m:#{elname}" } end n.genre :path => 'm:genre' do |n1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.geographic :path => 'm:geographic' do |n1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.geographicCode :path => 'm:geographicCode' do |gc| Mods::AUTHORITY_ATTRIBS.each { |attr_name| gc.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # convenience method gc.translated_value :path => '.', :accessor => lambda { |gc_node| code_val ||= gc_node.text xval = nil if code_val case gc_node. when 'marcgac' xval = MARC_GEOGRAPHIC_AREA[code_val] when 'marccountry' xval = MARC_COUNTRY[code_val] end end xval } end n.hierarchicalGeographic :path => 'm:hierarchicalGeographic' do |n1| Mods::Subject::HIER_GEO_CHILD_ELEMENTS.each { |elname| n1.send elname, :path => "m:#{elname}" } Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # Note: 'name' is used by Nokogiri n.name_el :path => 'm:name' do |t1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| t1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.personal_name :path => 'm:name[@type="personal"]' n.corporate_name :path => 'm:name[@type="corporate"]' n.conference_name :path => 'm:name[@type="conference"]' n.occupation :path => 'm:occupation' do |n1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.temporal :path => 'm:temporal' do |n1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } # date attributes as attributes Mods::DATE_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.titleInfo :path => 'm:titleInfo' do |t1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| t1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end n.topic :path => 'm:topic' do |n1| Mods::AUTHORITY_ATTRIBS.each { |attr_name| n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end end # t.subject # TABLE_OF_CONTENTS --------------------------------------------------------------------- t.tableOfContents :path => '/m:mods/m:tableOfContents' t._tableOfContents :path => '//m:tableOfContents' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.shareable :path => '@shareable', :accessor => lambda { |a| a.text } n.type_at :path => '@type', :accessor => lambda { |a| a.text } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # TARGET_AUDIENCE ----------------------------------------------------------------------- t.targetAudience :path => '/m:mods/m:targetAudience' t._targetAudience :path => '//m:targetAudience' do |n| n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } Mods::AUTHORITY_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } Mods::LANG_ATTRIBS.each { |attr_name| n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } } end # TITLE_INFO ---------------------------------------------------------------------------- t.title_info :path => '/m:mods/m:titleInfo' t._title_info :path => '//m:titleInfo' do |n| Mods::TitleInfo::ATTRIBUTES.each { |attr_name| if attr_name != 'type' n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text } else n.type_at :path => "@#{attr_name}", :accessor => lambda { |a| a.text } end } n.title :path => 'm:title' n.subTitle :path => 'm:subTitle' n.nonSort :path => 'm:nonSort' n.partNumber :path => 'm:partNumber' n.partName :path => 'm:partName' # convenience method n.sort_title :path => '.', :accessor => lambda { |node| if node.type_at != "alternative" || (node.type_at == "alternative" && mods_ng_xml.xpath('/m:mods/m:titleInfo', {'m' => Mods::MODS_NS}).size == 1) node.title.text + (!node.subTitle.text.empty? ? "#{@title_delimiter}#{node.subTitle.text}" : "" ) end } # convenience method n.full_title :path => '.', :accessor => lambda { |node| (!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) + node.title.text + (!node.subTitle.text.empty? ? "#{@title_delimiter}#{node.subTitle.text}" : "" ) } # convenience method n.short_title :path => '.', :accessor => lambda { |node| if node.type_at != "alternative" (!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) + node.title.text end } # convenience method n.alternative_title :path => '.', :accessor => lambda { |node| if node.type_at == "alternative" (!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) + node.title.text end } end # t._title_info # TYPE_OF_RESOURCE -------------------------------------------------------------------- t.typeOfResource :path => '/m:mods/m:typeOfResource' t._typeOfResource :path => '//m:typeOfResource' do |n| n.collection :path => '@collection', :accessor => lambda { |a| a.text } n.displayLabel :path => '@displayLabel', :accessor => lambda { |a| a.text } n.manuscript :path => '@manuscript', :accessor => lambda { |a| a.text } n.usage :path => '@usage', :accessor => lambda { |a| a.text } end end # terminology mods_ng_xml.nom! mods_ng_xml end |
#short_titles ⇒ Object
Returns Array of Strings, each containing the text contents of <mods><titleInfo> <nonSort> + ‘ ’ + <title> elements but not including any titleInfo elements with type=“alternative”.
141 142 143 |
# File 'lib/mods/record.rb', line 141 def short_titles @mods_ng_xml.title_info.short_title.map { |n| n } end |
#sort_title ⇒ Object
Returns String containing sortable title for this mods record.
156 157 158 |
# File 'lib/mods/record.rb', line 156 def sort_title @mods_ng_xml.title_info.sort_title.find { |n| !n.nil? } end |
#term_value(messages, sep = ' ') ⇒ String
get the value for the terms, as a String. f there are multiple values, they will be joined with the separator.
If there are no values, the result will be nil.
93 94 95 96 97 |
# File 'lib/mods/record.rb', line 93 def term_value , sep = ' ' vals = term_values return nil if !vals val = vals.join sep end |
#term_values(messages) ⇒ Array<String>
get the values for the terms, as an Array. If there are no values, the result will be nil.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/mods/record.rb', line 104 def term_values case when Symbol nodes = send() when String nodes = send(.to_sym) when Array obj = self .each { |msg| if msg.is_a? Symbol obj = obj.send(msg) elsif msg.is_a? String obj = obj.send(msg.to_sym) else raise ArgumentError, "term_values called with Array containing unrecognized class: #{msg.class}, #{.inspect}", caller end } nodes = obj else raise ArgumentError, "term_values called with unrecognized argument class: #{.class}", caller end vals = [] if nodes nodes.each { |n| vals << n.text unless n.text.empty? } end return nil if vals.empty? vals rescue NoMethodError raise ArgumentError, "term_values called with unknown argument: #{.inspect}", caller end |