Class: MathMetadata::Reference
- Inherits:
-
Object
- Object
- MathMetadata::Reference
- Defined in:
- lib/math_metadata_lookup/reference.rb
Constant Summary collapse
- ARTICLE_REFERENCE_1_RE =
1=authors, 2=title, 3=publication, 4=year, 5=range
%r{([^:]+):\s*(.*?),\s*([^,]+),\s*\((\d{4})\)\s*,\s*([^ ]+)\s*.*?}mi
- ARTICLE_REFERENCE_2_RE =
1=authors, 2=title, 3=publication, 4=range, 5=publisher, 6=place, 7=year
%r{([^:]+):\s*(.*?),\s*(.*?,\s*[^,]+,\s*[^,]+,\s*[^,]+),\s*pp\.\s*([^,]+?),\s*([^,]+),\s*(.*?),\s*(\d{4})\s*.*?}mi
- ARTICLE_REFERENCE_3_RE =
1=authors, 2=title, 3=range, 4=publication, 5=place, 6=year
%r{([^:]+):\s*(.*?),\s*pp\.\s*([^,]+?),\s*([^,]+),\s*(.*?),\s*(\d{4})}mi
- ARTICLE_REFERENCE_4_RE =
1=authors, 2=title, 3=publication, 4=publisher, 5=place, 6=year
%r{([^:]+):\s*(.*?),\s*(.*?),\s*([^,]+),\s*([^,]+),\s*(\d{4})\s*.*?}mi
- ARTICLE_REFERENCE_5_RE =
1=authors, 2=title, 4=publisher, 5=place, 6=year
%r{([^:]+):\s*(.*?),\s*(.*?),\s*([^,]+),\s*(\d{4})\s*.*?}mi
- ARTICLE_REFERENCE_6_RE =
1=authors, 2=title, 3=publisher, 4=place, 5=year
%r{([^:]+):\s*(.*?),\s*([^,]+),\s*([^,]+),\s*(\d{4})\s*}mi
- ARTICLE_REFERENCE_7_RE =
1=authors, 2=title, 3=publication, 4=year, 5=range
%r{([^:]+):\s*(.*),\s*(.*?,\s*\d+)\s*\((\d{4})\),\s*([^ ]+)\s*.*?}mi
- ARTICLE_REFERENCE_8_RE =
1=authors, 2=title, 3=publication, 4=year, 5=range
%r{([^:]+):\s*(.*),\s*(.*?)\s*\((\d{4})\),\s*([^ ]+)\s*.*?}mi
- ARTICLE_REFERENCE_9_RE =
1=authors, 2=title, 3=publisher, 4=place
%r{([^:]+):\s*(.*?),\s*([^,]+),\s*(.*)}mi
- ARTICLE_REFERENCE_10_RE =
1=authors, 2=title, 3=publication
%r{([^:]+):\s*(.*?),\s*(.*?)\s*.*?}mi
- ARTICLE_REFERENCE_11_RE =
1=authors, 2=title, 3=place, 4=year
%r{([^:]+):\s*(.*),(.*?)\s+(\d{4})}mi
Instance Attribute Summary collapse
-
#article ⇒ Object
Returns the value of attribute article.
-
#number ⇒ Object
Returns the value of attribute number.
-
#reg ⇒ Object
Returns the value of attribute reg.
-
#source ⇒ Object
Returns the value of attribute source.
-
#suffix ⇒ Object
Returns the value of attribute suffix.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(str = nil, i = 1) ⇒ Reference
constructor
A new instance of Reference.
Constructor Details
#initialize(str = nil, i = 1) ⇒ Reference
Returns a new instance of Reference.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/math_metadata_lookup/reference.rb', line 34 def initialize( str=nil, i=1 ) @number = i if str.kind_of?(Article) @source = @suffix = nil @article = str else @source = str @article, @suffix = Reference.parse(str) unless str.to_s.empty? end end |
Instance Attribute Details
#article ⇒ Object
Returns the value of attribute article.
32 33 34 |
# File 'lib/math_metadata_lookup/reference.rb', line 32 def article @article end |
#number ⇒ Object
Returns the value of attribute number.
32 33 34 |
# File 'lib/math_metadata_lookup/reference.rb', line 32 def number @number end |
#reg ⇒ Object
Returns the value of attribute reg.
32 33 34 |
# File 'lib/math_metadata_lookup/reference.rb', line 32 def reg @reg end |
#source ⇒ Object
Returns the value of attribute source.
32 33 34 |
# File 'lib/math_metadata_lookup/reference.rb', line 32 def source @source end |
#suffix ⇒ Object
Returns the value of attribute suffix.
32 33 34 |
# File 'lib/math_metadata_lookup/reference.rb', line 32 def suffix @suffix end |
Class Method Details
.parse(str) ⇒ Object
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 |
# File 'lib/math_metadata_lookup/reference.rb', line 46 def self.parse( str ) article = Article.new rnumber = 0 suffix = nil found = [] (1..11).each do |j| # 1=authors, 2=title, 3=publication, 4=year, 5=range, 6=id, 7=place, 8=publisher re = eval("Reference::ARTICLE_REFERENCE_#{j}_RE") if str =~ re case j when 1 # 1=authors, 2=title, 3=publication, 4=year, 5=range, 6=id found = [$1, $2, $3, $4, MathMetadata.normalize_range($5), nil] when 2 # 1=authors, 2=title, 3=publication, 4=range, 5=publisher, 6=place, 7=year, 8=id found = [$1, $2, $3, $7, MathMetadata.normalize_range($4), nil, $6, $5] when 3 # 1=authors, 2=title, 3=range, 4=publication, 5=place, 6=year found = [$1, $2, $4, $6, MathMetadata.normalize_range($3), nil, $5] when 4 # 1=authors, 2=title, 3=publication, 4=publisher, 5=place, 6=year, 7=id found = [$1, $2, $3, $6, nil, nil, $5, $4] when 5 # 1=authors, 2=title, 3=publisher, 4=place, 5=year, 6=id found = [$1, $2, nil, $5, nil, nil, $4, $3] when 6 # 1=authors, 2=title, 3=publisher, 4=place, 5=year, 6=id found = [$1, $2, nil, $5, nil, nil, $4, $3] when 7 # 1=authors, 2=title, 3=publication, 4=year, 5=range, 6=id found = [$1, $2, $3, $4, MathMetadata.normalize_range($5), nil] when 8 # 1=authors, 2=title, 3=publication, 4=year, 5=range, 6=id found = [$1, $2, $3, $4, MathMetadata.normalize_range($5), nil] when 9 # 1=authors, 2=title, 3=publisher, 4=place found = [$1, $2, nil, nil, nil, nil, $4, $3] when 10 # 1=authors, 2=title, 3=publication, 4=id found = [$1, $2, $3, nil, nil, nil, nil, nil] when 11 # 1=authors, 2=title, 3=place, 4=year found = [$1, $2, nil, $4, nil, nil, $3] end rnumber = j break end end [:authors, :title, :publication, :year, :range, :id, :place, :publisher].each_with_index do |key, idx| article[key] = found[idx] end article. = Reference. article. [article, suffix, rnumber] end |
.split_authors(str) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/math_metadata_lookup/reference.rb', line 104 def self.( str ) res = [ /;\s*/, /,?\s*(?:and|und|et)\s+/, /(\S+,\s*[^,]+),?\s*/ ] = [str] res.each do |re| = .map{|a| a.to_s.split(re)}.flatten end .delete_if{|a| a.strip.empty?} end |