openstax_content 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ require 'aws-sdk-s3'
2
+
3
+ class OpenStax::Content::S3
4
+ def initialize
5
+ @ls = {}
6
+ end
7
+
8
+ def bucket_name
9
+ OpenStax::Content.bucket_name
10
+ end
11
+
12
+ def bucket_configured?
13
+ !bucket_name.nil? && !bucket_name.empty?
14
+ end
15
+
16
+ def client
17
+ @client ||= Aws::S3::Client.new(
18
+ region: OpenStax::Content.s3_region,
19
+ access_key_id: OpenStax::Content.s3_access_key_id,
20
+ secret_access_key: OpenStax::Content.s3_secret_access_key
21
+ )
22
+ end
23
+
24
+ def ls(archive_version = nil)
25
+ return @ls[archive_version] unless @ls[archive_version].nil?
26
+ return unless bucket_configured?
27
+
28
+ archive_path = OpenStax::Content.archive_path.chomp('/')
29
+
30
+ if archive_version.nil?
31
+ prefix = "#{archive_path}/"
32
+ delimiter = '/'
33
+ else
34
+ prefix = "#{archive_path}/#{archive_version}/contents/"
35
+ delimiter = ':'
36
+ end
37
+
38
+ @ls[archive_version] = client.list_objects_v2(
39
+ bucket: bucket_name, prefix: prefix, delimiter: delimiter
40
+ ).flat_map(&:common_prefixes).map do |common_prefix|
41
+ common_prefix.prefix.sub(prefix, '').chomp(delimiter)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,18 @@
1
+ class OpenStax::Content::Title
2
+ attr_reader :book_location, :text
3
+
4
+ def initialize(title)
5
+ return if title.nil?
6
+
7
+ @text = title
8
+
9
+ part = Nokogiri::HTML.fragment(title)
10
+ number_node = part.at_css('.os-number')
11
+ unless number_node.nil?
12
+ @book_location = number_node.text.gsub(/[^\.\d]/, '').split('.').map do |number|
13
+ Integer(number) rescue nil
14
+ end.compact
15
+ end
16
+ @book_location = [] if @book_location.nil?
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module OpenStax
2
+ module Content
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openstax_content
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dante Soares
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-s3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Ruby bindings to read and parse the OpenStax ABL and the content archive
112
+ email:
113
+ - dante.m.soares@rice.edu
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - LICENSE
119
+ - README.md
120
+ - lib/openstax/content.rb
121
+ - lib/openstax/content/abl.rb
122
+ - lib/openstax/content/archive.rb
123
+ - lib/openstax/content/book.rb
124
+ - lib/openstax/content/book_part.rb
125
+ - lib/openstax/content/custom_css.rb
126
+ - lib/openstax/content/fragment.rb
127
+ - lib/openstax/content/fragment/embedded.rb
128
+ - lib/openstax/content/fragment/exercise.rb
129
+ - lib/openstax/content/fragment/html.rb
130
+ - lib/openstax/content/fragment/interactive.rb
131
+ - lib/openstax/content/fragment/optional_exercise.rb
132
+ - lib/openstax/content/fragment/reading.rb
133
+ - lib/openstax/content/fragment/video.rb
134
+ - lib/openstax/content/fragment_splitter.rb
135
+ - lib/openstax/content/page.rb
136
+ - lib/openstax/content/s3.rb
137
+ - lib/openstax/content/title.rb
138
+ - lib/openstax/content/version.rb
139
+ homepage: https://github.com/openstax/content-ruby
140
+ licenses:
141
+ - AGPL-3.0
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubygems_version: 3.2.19
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Ruby bindings to read and parse the OpenStax ABL and the content archive
162
+ test_files: []