brrr 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c9ce6e61071657c81f90034aaf57bc732094eb48d909c080977f225482ac5897
4
+ data.tar.gz: 530fd41a7a0b052ed6ebd54ee128cd8ed59380cd6bccfaf58d5228477139fec4
5
+ SHA512:
6
+ metadata.gz: d809d85c657fec4d2606c8cf085523dfc484f1e99dd04d0bc78e790ec54bf3195421bed350fc9142d3c99fe8ab63e7d4a7005900f3738c10e685fce633783ce0
7
+ data.tar.gz: be049ad7eab0010fc5bcfa81c41d5a4e738910f073faaa3a7c534783c4015331f832f62421cdce15bf79a266b67836b7caaaeb48004f486ab2d4602ced6004f8
@@ -0,0 +1,17 @@
1
+ module Brrr
2
+ class Channel
3
+ class Category < Feed::Element
4
+ def as_string
5
+ node.content
6
+ end
7
+
8
+ def as_array
9
+ node.content.split("/")
10
+ end
11
+
12
+ def domain
13
+ node.attribute("domain")&.value
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module Brrr
2
+ class Channel
3
+ class Cloud < Feed::Element
4
+
5
+ def initialize(node)
6
+ super
7
+ end
8
+
9
+ def domain
10
+ node.attribute("domain").value
11
+ end
12
+
13
+ def port
14
+ Integer(node.attribute("port").value)
15
+ end
16
+
17
+ def path
18
+ node.attribute("path").value
19
+ end
20
+
21
+ def register_procedure
22
+ node.attribute("registerProcedure").value
23
+ end
24
+
25
+ def protocol
26
+ node.attribute("protocol").value
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ module Brrr
2
+ class Channel
3
+ class Image < Feed::Element
4
+
5
+ def initialize(node)
6
+ super
7
+ end
8
+
9
+ def url
10
+ node.at_xpath("./url").content
11
+ end
12
+
13
+ def title
14
+ node.at_xpath("./title").content
15
+ end
16
+
17
+ def link
18
+ node.at_xpath("./link").content
19
+ end
20
+
21
+ def width
22
+ node.at_xpath("./width")&.content&.to_i
23
+ end
24
+
25
+ def height
26
+ node.at_xpath("./height")&.content&.to_i
27
+ end
28
+
29
+ def description
30
+ node.at_xpath("./description")&.content
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ module Brrr
2
+ class Channel
3
+ class TextInput < Feed::Element
4
+
5
+ def initialize(node)
6
+ super
7
+ end
8
+
9
+ def title
10
+ node.at_xpath("./title").content
11
+ end
12
+
13
+ def description
14
+ node.at_xpath("./description").content
15
+ end
16
+
17
+ def name
18
+ node.at_xpath("./name").content
19
+ end
20
+
21
+ def link
22
+ node.at_xpath("./link").content
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,112 @@
1
+ module Brrr
2
+ class Channel
3
+ attr_writer :document
4
+
5
+ def initialize(xml)
6
+ self.document = Nokogiri.XML(xml)
7
+ end
8
+
9
+ def items
10
+ @items ||= channel_items
11
+ end
12
+
13
+ def title
14
+ @title ||= document.at_xpath("//title").content
15
+ end
16
+
17
+ def link
18
+ @link ||= document.at_xpath("//link").content
19
+ end
20
+
21
+ def description
22
+ @description ||= document.at_xpath("//description").content
23
+ end
24
+
25
+ def language
26
+ @language ||= document.at_xpath("//language")&.content
27
+ end
28
+
29
+ def copyright
30
+ @copyright ||= document.at_xpath("//copyright")&.content
31
+ end
32
+
33
+ def managing_editor
34
+ @managing_editor ||= document.at_xpath("//managingEditor")&.content
35
+ end
36
+
37
+ def web_master
38
+ @web_master ||= document.at_xpath("//webMaster")&.content
39
+ end
40
+
41
+ def pub_date
42
+ @pub_date ||= document.at_xpath("//pubDate")&.content
43
+ end
44
+
45
+ def last_build_date
46
+ @last_build_date ||= document.at_xpath("//lastBuildDate")&.content
47
+ end
48
+
49
+ def categories
50
+ @categories ||= channel_categories
51
+ end
52
+
53
+ def generator
54
+ @generator ||= document.at_xpath("//generator")&.content
55
+ end
56
+
57
+ def docs
58
+ @docs ||= document.at_xpath("//docs")&.content
59
+ end
60
+
61
+ def cloud
62
+ @cloud ||= Cloud.new(document.at_xpath("//cloud"))
63
+ end
64
+
65
+ def ttl
66
+ @ttl ||= Integer(document.at_xpath("//ttl")&.content)
67
+ end
68
+
69
+ def image
70
+ @image ||= Image.new(document.at_xpath("//image"))
71
+ end
72
+
73
+ def rating
74
+ @rating ||= document.at_xpath("//rating")&.content
75
+ end
76
+
77
+ def text_input
78
+ @text_input ||= TextInput.new(document.at_xpath("//textInput"))
79
+ end
80
+
81
+ def skip_hours
82
+ @skip_hours ||= channel_skip_hours
83
+ end
84
+
85
+ def skip_days
86
+ @skip_days ||= channel_skip_days
87
+ end
88
+
89
+ private
90
+
91
+ attr_reader :document
92
+
93
+ def channel_items
94
+ item_set = document.xpath("//item")
95
+ item_set.map { |item| Brrr::Item.new(self, item) }
96
+ end
97
+
98
+ def channel_categories
99
+ category_set = document.xpath("//category")
100
+ category_set.map { |category| Category.new(category) }
101
+ end
102
+
103
+ def channel_skip_hours
104
+ hour_set = document.xpath("//skipHours/hour")
105
+ hour_set.map { |hour| hour.content.to_i }
106
+ end
107
+
108
+ def channel_skip_days
109
+ document.xpath("//skipDays/day").map(&:content)
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,19 @@
1
+ module Brrr
2
+ module Feed
3
+ class Element
4
+ attr_writer :node
5
+
6
+ def initialize(node)
7
+ self.node = node
8
+ end
9
+
10
+ def value
11
+ node.content unless node.content.empty?
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :node
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Brrr
2
+ class Item
3
+ class Enclosure < Feed::Element
4
+ def url
5
+ node.attribute("url").value
6
+ end
7
+
8
+ def length
9
+ Integer(node.attribute("length").value)
10
+ end
11
+
12
+ def type
13
+ node.attribute("type").value
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Brrr
2
+ class Item
3
+ class Guid < Feed::Element
4
+ def is_permalink?
5
+ @is_permalink ||= node.attribute("isPermaLink")&.value == "true"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Brrr
2
+ class Item
3
+ class Source < Feed::Element
4
+ def url
5
+ node.attribute("url").value
6
+ end
7
+ end
8
+ end
9
+ end
data/lib/brrr/item.rb ADDED
@@ -0,0 +1,68 @@
1
+ module Brrr
2
+ class Item
3
+ attr_accessor :channel
4
+ attr_writer :node
5
+
6
+ def initialize(channel, node)
7
+ self.channel = channel
8
+ self.node = node
9
+ end
10
+
11
+ def title
12
+ @title ||= node.at_xpath("./title")&.content
13
+ end
14
+
15
+ def link
16
+ @link ||= node.at_xpath("./link")&.content
17
+ end
18
+
19
+ def description
20
+ @description ||= node.at_xpath("./description")&.content
21
+ end
22
+
23
+ def author
24
+ @author ||= node.at_xpath("./author")&.content
25
+ end
26
+
27
+ def comments
28
+ @comments ||= node.at_xpath("./comments")&.content
29
+ end
30
+
31
+ def pub_date
32
+ @pub_date ||= parsed_pub_date
33
+ end
34
+
35
+ def guid
36
+ @guid ||= Item::Guid.new(node)
37
+ end
38
+
39
+ def source
40
+ @source ||= Item::Source.new(node)
41
+ end
42
+
43
+ def categories
44
+ @categories ||= item_categories
45
+ end
46
+
47
+ def enclosure
48
+ @enclosure ||= Item::Enclosure.new(node)
49
+ end
50
+
51
+ private
52
+
53
+ attr_reader :node
54
+
55
+ def item_categories
56
+ category_nodeset = node.xpath("./category")
57
+ return if category_nodeset.empty?
58
+
59
+ category_nodeset.map { |node| Channel::Category.new(node) }
60
+ end
61
+
62
+ def parsed_pub_date
63
+ pub_date = node.at_xpath("./pubDate")&.content
64
+ return unless pub_date
65
+ DateTime.parse(pub_date)
66
+ end
67
+ end
68
+ end
data/lib/brrr.rb ADDED
@@ -0,0 +1,24 @@
1
+ require "date"
2
+ require "nokogiri"
3
+ require "open-uri"
4
+
5
+ require_relative "brrr/feed/element"
6
+ require_relative "brrr/channel"
7
+ require_relative "brrr/item"
8
+ require_relative "brrr/channel/category"
9
+ require_relative "brrr/channel/cloud"
10
+ require_relative "brrr/channel/image"
11
+ require_relative "brrr/channel/text_input"
12
+ require_relative "brrr/item/enclosure"
13
+ require_relative "brrr/item/guid"
14
+ require_relative "brrr/item/source"
15
+
16
+ module Brrr
17
+ def self.from_url(url)
18
+ URI.open(url) { |file| return Channel.new(file) }
19
+ end
20
+
21
+ def self.from_file(path)
22
+ File.open { |file| return Channel.new(file) }
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brrr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - bobby the count
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/brrr.rb
62
+ - lib/brrr/channel.rb
63
+ - lib/brrr/channel/category.rb
64
+ - lib/brrr/channel/cloud.rb
65
+ - lib/brrr/channel/image.rb
66
+ - lib/brrr/channel/text_input.rb
67
+ - lib/brrr/feed/element.rb
68
+ - lib/brrr/item.rb
69
+ - lib/brrr/item/enclosure.rb
70
+ - lib/brrr/item/guid.rb
71
+ - lib/brrr/item/source.rb
72
+ homepage: https://codeberg.org/bobby_the_count/brrr
73
+ licenses:
74
+ - LGPL-3.0
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.4.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A simple RSS library
95
+ test_files: []