iso-bib-item 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43345dd1988738e08a77bc1fbd3e794ee25ec341
4
+ data.tar.gz: e8dcfdb32b17d39821c37aaa49ec4a2ff23557a8
5
+ SHA512:
6
+ metadata.gz: 98f60fea9b8cd84c7c8aa4ed133bebddd3b140a1ea29465498351166e258c4e794df056c136de74f1c9b5eab0c30f3d2d849d9d4a43347086cb2cc63507410ed
7
+ data.tar.gz: 2daf622569fbed7f20ba4da92ae4c14a53156247f7ab44b1ca7733e49605c82165d7cd96916859d34394cadc49473f6666cbedae5a5bd4f5978d9f214ce84330
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4.0
3
+ Metrics/BlockLength:
4
+ ExcludedMethods: ['describe', 'context', 'it', 'let']
5
+ Style/Encoding:
6
+ Exclude:
7
+ - 'spec/**/*.rb'
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in iso-bib-item.gemspec
6
+ gemspec
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ iso-bib-item (0.1.0)
5
+ isoics
6
+ nokogiri
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ byebug (10.0.0)
12
+ coderay (1.1.2)
13
+ diff-lcs (1.3)
14
+ docile (1.3.0)
15
+ isoics (0.1.5)
16
+ json (2.1.0)
17
+ method_source (0.9.0)
18
+ mini_portile2 (2.3.0)
19
+ nokogiri (1.8.2)
20
+ mini_portile2 (~> 2.3.0)
21
+ pry (0.11.3)
22
+ coderay (~> 1.1.0)
23
+ method_source (~> 0.9.0)
24
+ pry-byebug (3.6.0)
25
+ byebug (~> 10.0)
26
+ pry (~> 0.10)
27
+ rake (10.5.0)
28
+ rspec (3.7.0)
29
+ rspec-core (~> 3.7.0)
30
+ rspec-expectations (~> 3.7.0)
31
+ rspec-mocks (~> 3.7.0)
32
+ rspec-core (3.7.1)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-expectations (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-mocks (3.7.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.7.0)
40
+ rspec-support (3.7.1)
41
+ simplecov (0.16.1)
42
+ docile (~> 1.1)
43
+ json (>= 1.8, < 3)
44
+ simplecov-html (~> 0.10.0)
45
+ simplecov-html (0.10.2)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 1.16)
52
+ iso-bib-item!
53
+ pry-byebug
54
+ rake (~> 10.0)
55
+ rspec (~> 3.0)
56
+ simplecov
57
+
58
+ BUNDLED WITH
59
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Andrei Kislichenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # IsoBibItem
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/iso/bib/item`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'iso-bib-item'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install iso-bib-item
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/iso-bib-item.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "iso/bib/item"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'iso_bib_item/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'iso-bib-item'
9
+ spec.version = IsoBibItem::VERSION
10
+ spec.authors = ['Ribose Inc.']
11
+ spec.email = ['android.2net@gmail.com']
12
+
13
+ spec.summary = %(IsoBibItem: Ruby ISOXMLDOC impementation.)
14
+ spec.description = %(IsoBibItem: Ruby ISOXMLDOC impementation.)
15
+ spec.homepage = 'https://github.com/riboseinc/gdbib'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.16'
26
+ spec.add_development_dependency 'pry-byebug'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'simplecov'
30
+
31
+ spec.add_dependency 'isoics'
32
+ spec.add_dependency 'nokogiri'
33
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'iso_bib_item/version'
4
+ require 'iso_bib_item/iso_bibliographic_item'
5
+
6
+ # ISO bibliographic model.
7
+ module IsoBibItem
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module IsoBibItem
6
+ # Bibliographic date.
7
+ class BibliographicDate
8
+ # @return [String]
9
+ attr_reader :type
10
+
11
+ # @return [Time]
12
+ attr_reader :from
13
+
14
+ # @return [Time]
15
+ attr_reader :to
16
+
17
+ # @param type [String] "published", "accessed", "created", "activated"
18
+ # @param from [String]
19
+ # @param to [String]
20
+ def initialize(type:, from:, to: nil)
21
+ @type = type
22
+ @from = Time.strptime(from, '%Y-%d')
23
+ @to = Time.strptime(to, '%Y-%d') if to
24
+ end
25
+
26
+ def to_xml(builder, **opts)
27
+ builder.date(type: type) do
28
+ builder.from(opts[:no_year] ? '--' : from.year)
29
+ builder.to to.year if to
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,173 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'iso_bib_item/formatted_string'
4
+ require 'iso_bib_item/contribution_info'
5
+ require 'iso_bib_item/bibliographic_date'
6
+
7
+ module IsoBibItem
8
+ # module BibItemType
9
+ # ARTICLE = 'article'
10
+ # BOOK = 'book'
11
+ # BOOKLET = 'booklet'
12
+ # CONFERENCE = 'conference'
13
+ # MANUAL = 'manual'
14
+ # PROCEEDINGS = 'proceedings'
15
+ # PRESENTATION = 'presentation'
16
+ # THESIS = 'thesis'
17
+ # TECHREPORT = 'techreport'
18
+ # STANDARD = 'standard'
19
+ # UNPUBLISHED = 'unpublished'
20
+ # end
21
+
22
+ # Document identifier.
23
+ class DocumentIdentifier
24
+ # @return [String]
25
+ attr_reader :id
26
+
27
+ # @return [String]
28
+ attr_reader :type
29
+
30
+ def initialize(id)
31
+ @id = id
32
+ end
33
+ end
34
+
35
+ # Copyright association.
36
+ class CopyrightAssociation
37
+ # @return [Time]
38
+ attr_reader :from
39
+
40
+ # @return [Time]
41
+ attr_reader :to
42
+
43
+ # @return [Isobib::ContributionInfo]
44
+ attr_reader :owner
45
+
46
+ # @param owner [Hash{name=>String, abbreviation=>String, url=>String}]
47
+ # contributor
48
+ # @param from [String] date
49
+ # @param to [String] date
50
+ def initialize(owner:, from:, to: nil)
51
+ @owner = ContributionInfo.new entity: Organization.new(owner)
52
+ @from = Time.strptime(from, '%Y') unless from.empty?
53
+ @to = Time.parse(to) if to
54
+ end
55
+
56
+ def to_xml(builder)
57
+ builder.copyright do
58
+ builder.from from.year
59
+ builder.to to.year if to
60
+ builder.owner { owner.to_xml builder }
61
+ end
62
+ end
63
+ end
64
+
65
+ # Typed URI
66
+ class TypedUri
67
+ # @return [Symbol] :src/:obp/:rss
68
+ attr_reader :type
69
+ # @retutn [URI]
70
+ attr_reader :content
71
+
72
+ # @param type [String] src/obp/rss
73
+ # @param content [String]
74
+ def initialize(type:, content:)
75
+ @type = type
76
+ @content = URI content if content
77
+ end
78
+
79
+ def to_xml(builder)
80
+ builder.source(content.to_s, type: type)
81
+ end
82
+ end
83
+
84
+ # Bibliographic item
85
+ class BibliographicItem
86
+ # @return [Array<IsoBibItem::FormattedString>]
87
+ attr_reader :title
88
+
89
+ # @return [Array<IsoBibItem::TypedUri>]
90
+ attr_reader :source
91
+
92
+ # @return [IsoBibItem::BibItemType]
93
+ attr_reader :type
94
+
95
+ # @return [Array<IsoBibItem::DocumentIdentifier>]
96
+ attr_reader :docidentifier
97
+
98
+ # @return [Array<IsoBibItem::BibliographicDate>]
99
+ attr_reader :dates
100
+
101
+ # @return [Array<IsoBibItem::ContributionInfo>]
102
+ attr_reader :contributors
103
+
104
+ # @return [String]
105
+ attr_reader :edition
106
+
107
+ # @return [Array<IsoBibItem::FormattedString>]
108
+ attr_reader :notes
109
+
110
+ # @return [Array<String>] language Iso639 code
111
+ attr_reader :language
112
+
113
+ # @return [Array<String>] script Iso15924 code
114
+ attr_reader :script
115
+
116
+ # @return [IsoBibItem::FormattedString]
117
+ attr_reader :formatted_ref
118
+
119
+ # @!attribute [r] abstract
120
+ # @return [Arra<IsoBibItem::FormattedString>]
121
+
122
+ # @return [IsoBibItem::DocumentStatus]
123
+ attr_reader :status
124
+
125
+ # @return [IsoBibItem::CopyrightAssociation]
126
+ attr_reader :copyright
127
+
128
+ # @return [IsoBibItem::DocRelationCollection]
129
+ attr_reader :relations
130
+
131
+ # @param language [Arra<String>]
132
+ # @param script [Array<String>]
133
+ # @param dates [Array<Hash{type=>String, from=>String, to=>String}>]
134
+ # @param contributors [Array<Hash{entity=>Hash{name=>String, url=>String,
135
+ # abbreviation=>String}, roles=>Array<String>}>]
136
+ # @param abstract [Array<Hash{content=>String, language=>String,
137
+ # script=>String, type=>String}>]
138
+ # @param relations [Array<Hash{type=>String, identifier=>String}>]
139
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
140
+ def initialize(**args)
141
+ @title = []
142
+ @docidentifier = []
143
+ @dates = (args[:dates] || []).map { |d| BibliographicDate.new(d) }
144
+ @contributors = (args[:contributors] || []).map do |c|
145
+ ContributionInfo.new(entity: Organization.new(c[:entity]),
146
+ role: c[:roles])
147
+ end
148
+ @notes = []
149
+ @language = args[:language]
150
+ @script = args[:script]
151
+ @abstract = (args[:abstract] || []).map do |a|
152
+ FormattedString.new(a)
153
+ end
154
+ @relations = DocRelationCollection.new(args[:relations] || [])
155
+ end
156
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
157
+
158
+ # @param docid [DocumentIdentifier]
159
+ # def add_docidentifier(docid)
160
+ # @docidentifier << docid
161
+ # end
162
+
163
+ # @param lang [String] language code Iso639
164
+ # @return [IsoBibItem::FormattedString, Array<IsoBibItem::FormattedString>]
165
+ def abstract(lang: nil)
166
+ if lang
167
+ @abstract.find { |a| a.language.include? lang }
168
+ else
169
+ @abstract
170
+ end
171
+ end
172
+ end
173
+ end