openstax_content 1.0.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ce0c0361f6d9e8205eb18893bb7d4f4bf726a2adf6fab3fe35649c56ae55876
4
- data.tar.gz: ccec97c10020878437487261de88a742ccf16480e178227a323420ed2f9fe4fd
3
+ metadata.gz: 82eddc2890b74eeea7b59646cda86001dbb0385ddc00ad874ae5f69573441d57
4
+ data.tar.gz: a8f83e6c1a5bb7c0e5cda4e6171da21da8cfce91e1e89c74ecc954a8299015eb
5
5
  SHA512:
6
- metadata.gz: 419d040e582db3b9233e2a6ebfcc3a6ad5bf908ed656a74aa67ecab1f111ad9278947e9bae3dab41d0479f36c7ad8750cabdac760dd6ca8ba73acacc8b94841d
7
- data.tar.gz: aafb9064479bdaa157c557018b46c442f9c9abc4f0ce8fb48e12b7f81c8f0f09f2bba2829db6227bc7d5c36831b9909bb581839cea80da65cea87a5b807d33a9
6
+ metadata.gz: 34fe275a54727deb10d3636fbc82cf3c9a86461d67f6695ea157209b71ae0ded2660d4c0e4f100af332c5db9bb5b8b54769ce22f060ff96d13e2b3be9a3f98cc
7
+ data.tar.gz: 05ec447981510aac02c672ba6606aaf111ffe785ffdc5b7a8d1a0223f7e8c3807da7168b61551e1acc23d48cf31134a6d080e2a65ee4864a7a2491787b85eac3
@@ -71,7 +71,9 @@ class OpenStax::Content::Abl
71
71
  uuid: book[:uuid],
72
72
  version: version[:commit_sha][0..6],
73
73
  slug: book[:slug],
74
- style: book[:style]
74
+ style: book[:style],
75
+ min_code_version: version[:min_code_version],
76
+ committed_at: commit_metadata[:committed_at]
75
77
  )
76
78
  end
77
79
  end
@@ -11,13 +11,20 @@ class OpenStax::Content::Archive
11
11
  @s3 ||= OpenStax::Content::S3.new
12
12
  end
13
13
 
14
+ def versions
15
+ @versions ||= s3.ls.reverse
16
+ end
17
+
14
18
  def version
15
- @version ||= s3.ls.last
19
+ @version || versions.first
20
+ end
21
+
22
+ def previous_version
23
+ versions[versions.index(version) + 1]
16
24
  end
17
25
 
18
26
  def base_url
19
- @base_url ||= "https://#{OpenStax::Content.domain}/#{
20
- OpenStax::Content.archive_path}/#{version}"
27
+ @base_url ||= "https://#{OpenStax::Content.domain}/#{OpenStax::Content.archive_path}/#{version}"
21
28
  end
22
29
 
23
30
  def url_for(object)
@@ -1,11 +1,15 @@
1
+ require 'forwardable'
1
2
  require_relative 'book_part'
2
3
 
3
4
  class OpenStax::Content::Book
4
5
  extend Forwardable
5
6
 
6
- attr_reader :archive, :uuid, :version, :slug, :style
7
+ attr_reader :archive, :uuid, :version, :slug, :style, :min_code_version, :committed_at
7
8
 
8
- def initialize(archive:, uuid:, version:, url: nil, hash: nil, slug: nil, style: nil)
9
+ def initialize(
10
+ archive:, uuid:, version:,
11
+ url: nil, hash: nil, slug: nil, style: nil, min_code_version: nil, committed_at: nil
12
+ )
9
13
  @archive = archive
10
14
  @uuid = uuid
11
15
  @version = version
@@ -13,20 +17,26 @@ class OpenStax::Content::Book
13
17
  @hash = hash
14
18
  @slug = slug
15
19
  @style = style
20
+ @min_code_version = min_code_version
21
+ @committed_at = committed_at
16
22
  end
17
23
 
18
- def url
19
- @url ||= archive.url_for "#{uuid}@#{version}"
24
+ def valid?
25
+ min_code_version.nil? || min_code_version <= archive.version
20
26
  end
21
27
 
22
- def hash
23
- @hash ||= archive.json url
28
+ def url
29
+ @url ||= archive.url_for "#{uuid}@#{version}"
24
30
  end
25
31
 
26
32
  def url_fragment
27
33
  @url_fragment ||= url.chomp('.json')
28
34
  end
29
35
 
36
+ def hash
37
+ @hash ||= archive.json url
38
+ end
39
+
30
40
  def baked
31
41
  @baked ||= hash['baked']
32
42
  end
@@ -32,7 +32,7 @@ class OpenStax::Content::Page
32
32
  node.at_css(feature_id_css)
33
33
  end
34
34
 
35
- def initialize(book: nil, hash: {}, uuid: nil, url: nil, title: nil, content: nil)
35
+ def initialize(book: nil, hash: {}, uuid: nil, url: nil, title: nil, slug: nil, content: nil)
36
36
  @uuid = uuid || hash['id']&.split('@', 2)&.first
37
37
  raise ArgumentError, 'Either uuid or hash with id key is required' if @uuid.nil?
38
38
 
@@ -40,11 +40,12 @@ class OpenStax::Content::Page
40
40
  @hash = hash
41
41
  @url = url
42
42
  @title = title || hash['title']
43
+ @slug = slug || hash['slug']
43
44
  @content = content
44
45
  end
45
46
 
46
47
  attr_accessor :chapter_section
47
- attr_reader :uuid, :hash
48
+ attr_reader :uuid, :hash, :slug
48
49
 
49
50
  def book
50
51
  raise ArgumentError, 'Book was not specified' if @book.nil?
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Content
3
- VERSION = '1.0.0'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_content
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dante Soares
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-01 00:00:00.000000000 Z
11
+ date: 2022-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3