micromicro 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +14 -0
  3. data/.gitignore +34 -0
  4. data/.gitmodules +3 -0
  5. data/.reek.yml +8 -0
  6. data/.rspec +2 -0
  7. data/.rubocop +3 -0
  8. data/.rubocop.yml +25 -0
  9. data/.ruby-version +1 -0
  10. data/.simplecov +11 -0
  11. data/.travis.yml +19 -0
  12. data/CHANGELOG.md +5 -0
  13. data/CONTRIBUTING.md +37 -0
  14. data/Gemfile +14 -0
  15. data/LICENSE +21 -0
  16. data/README.md +122 -0
  17. data/Rakefile +18 -0
  18. data/lib/micro_micro/collections/base_collection.rb +37 -0
  19. data/lib/micro_micro/collections/items_collection.rb +10 -0
  20. data/lib/micro_micro/collections/properties_collection.rb +18 -0
  21. data/lib/micro_micro/collections/relations_collection.rb +23 -0
  22. data/lib/micro_micro/document.rb +71 -0
  23. data/lib/micro_micro/implied_property.rb +25 -0
  24. data/lib/micro_micro/item.rb +151 -0
  25. data/lib/micro_micro/parsers/base_property_parser.rb +33 -0
  26. data/lib/micro_micro/parsers/date_time_parser.rb +85 -0
  27. data/lib/micro_micro/parsers/date_time_property_parser.rb +65 -0
  28. data/lib/micro_micro/parsers/embedded_markup_property_parser.rb +28 -0
  29. data/lib/micro_micro/parsers/implied_name_property_parser.rb +78 -0
  30. data/lib/micro_micro/parsers/implied_photo_property_parser.rb +69 -0
  31. data/lib/micro_micro/parsers/implied_url_property_parser.rb +61 -0
  32. data/lib/micro_micro/parsers/plain_text_property_parser.rb +39 -0
  33. data/lib/micro_micro/parsers/url_property_parser.rb +75 -0
  34. data/lib/micro_micro/parsers/value_class_pattern_parser.rb +92 -0
  35. data/lib/micro_micro/property.rb +116 -0
  36. data/lib/micro_micro/relation.rb +78 -0
  37. data/lib/micro_micro/version.rb +3 -0
  38. data/lib/micromicro.rb +39 -0
  39. data/micromicro.gemspec +28 -0
  40. metadata +128 -0
@@ -0,0 +1,78 @@
1
+ module MicroMicro
2
+ class Relation
3
+ # @param node [Nokogiri::XML::Element]
4
+ def initialize(node)
5
+ @node = node
6
+ end
7
+
8
+ # @return [String]
9
+ def href
10
+ @href ||= Absolutely.to_abs(base: node.document.url, relative: node['href'].strip)
11
+ end
12
+
13
+ # @return [String, nil]
14
+ def hreflang
15
+ @hreflang ||= node['hreflang']&.strip
16
+ end
17
+
18
+ # @return [String]
19
+ def inspect
20
+ format(%(#<#{self.class.name}:%#0x href: #{href.inspect}, rels: #{rels.inspect}>), object_id)
21
+ # format(%(#<#{self.class.name}:%#0x rels: #{rels}>), object_id)
22
+ end
23
+
24
+ # @return [String, nil]
25
+ def media
26
+ @media ||= node['media']&.strip
27
+ end
28
+
29
+ # @return [Hash{Symbol => String}]
30
+ def to_h
31
+ {
32
+ href: href,
33
+ rels: rels,
34
+ hreflang: hreflang,
35
+ media: media,
36
+ title: title,
37
+ type: type,
38
+ text: text
39
+ }.select { |_, value| value.present? }
40
+ end
41
+
42
+ # @return [Array<String>]
43
+ def rels
44
+ @rels ||= node['rel'].split.uniq.sort
45
+ end
46
+
47
+ # @return [String]
48
+ def text
49
+ @text ||= node.text
50
+ end
51
+
52
+ # @return [String, nil]
53
+ def title
54
+ @title ||= node['title']&.strip
55
+ end
56
+
57
+ # @return [String, nil]
58
+ def type
59
+ @type ||= node['type']&.strip
60
+ end
61
+
62
+ # @param context [Nokogiri::HTML::Document, Nokogiri::XML::Element]
63
+ # @return [Nokogiri::XML::NodeSet]
64
+ def self.nodes_from(context)
65
+ context.css('[href][rel]:not([rel=""])').reject { |node| (node.ancestors.map(&:name) & Document.ignored_node_names).any? }
66
+ end
67
+
68
+ # @param context [Nokogiri::HTML::Document, Nokogiri::XML::Element]
69
+ # @return [Array<MicroMicro::Relation>]
70
+ def self.relations_from(context)
71
+ nodes_from(context).map { |node| new(node) }
72
+ end
73
+
74
+ private
75
+
76
+ attr_reader :node
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module MicroMicro
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,39 @@
1
+ require 'absolutely'
2
+ require 'active_support/core_ext/array/grouping'
3
+ require 'active_support/core_ext/hash/deep_transform_values'
4
+ require 'active_support/core_ext/hash/keys'
5
+ require 'active_support/core_ext/hash/slice'
6
+ require 'active_support/core_ext/module/delegation'
7
+ require 'active_support/core_ext/object/blank'
8
+ require 'nokogiri'
9
+
10
+ require 'micro_micro/version'
11
+
12
+ require 'micro_micro/parsers/date_time_parser'
13
+ require 'micro_micro/parsers/value_class_pattern_parser'
14
+
15
+ require 'micro_micro/parsers/base_property_parser'
16
+ require 'micro_micro/parsers/date_time_property_parser'
17
+ require 'micro_micro/parsers/embedded_markup_property_parser'
18
+ require 'micro_micro/parsers/implied_name_property_parser'
19
+ require 'micro_micro/parsers/implied_photo_property_parser'
20
+ require 'micro_micro/parsers/implied_url_property_parser'
21
+ require 'micro_micro/parsers/plain_text_property_parser'
22
+ require 'micro_micro/parsers/url_property_parser'
23
+
24
+ require 'micro_micro/document'
25
+ require 'micro_micro/item'
26
+ require 'micro_micro/property'
27
+ require 'micro_micro/implied_property'
28
+ require 'micro_micro/relation'
29
+
30
+ require 'micro_micro/collections/base_collection'
31
+ require 'micro_micro/collections/items_collection'
32
+ require 'micro_micro/collections/properties_collection'
33
+ require 'micro_micro/collections/relations_collection'
34
+
35
+ module MicroMicro
36
+ def self.parse(markup, base_url)
37
+ Document.new(markup, base_url)
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/micro_micro/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 2.8')
5
+
6
+ spec.name = 'micromicro'
7
+ spec.version = MicroMicro::VERSION
8
+ spec.authors = ['Jason Garber']
9
+ spec.email = ['jason@sixtwothree.org']
10
+
11
+ spec.summary = 'Extract microformats2-encoded data from HTML documents.'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/jgarber623/micromicro'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|spec)/}) }
18
+ end
19
+
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
23
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
24
+
25
+ spec.add_runtime_dependency 'absolutely', '~> 3.1'
26
+ spec.add_runtime_dependency 'activesupport', '~> 6.0'
27
+ spec.add_runtime_dependency 'nokogiri', '~> 1.10'
28
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: micromicro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Garber
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: absolutely
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '6.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '6.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: '1.10'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ description: Extract microformats2-encoded data from HTML documents.
56
+ email:
57
+ - jason@sixtwothree.org
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".editorconfig"
63
+ - ".gitignore"
64
+ - ".gitmodules"
65
+ - ".reek.yml"
66
+ - ".rspec"
67
+ - ".rubocop"
68
+ - ".rubocop.yml"
69
+ - ".ruby-version"
70
+ - ".simplecov"
71
+ - ".travis.yml"
72
+ - CHANGELOG.md
73
+ - CONTRIBUTING.md
74
+ - Gemfile
75
+ - LICENSE
76
+ - README.md
77
+ - Rakefile
78
+ - lib/micro_micro/collections/base_collection.rb
79
+ - lib/micro_micro/collections/items_collection.rb
80
+ - lib/micro_micro/collections/properties_collection.rb
81
+ - lib/micro_micro/collections/relations_collection.rb
82
+ - lib/micro_micro/document.rb
83
+ - lib/micro_micro/implied_property.rb
84
+ - lib/micro_micro/item.rb
85
+ - lib/micro_micro/parsers/base_property_parser.rb
86
+ - lib/micro_micro/parsers/date_time_parser.rb
87
+ - lib/micro_micro/parsers/date_time_property_parser.rb
88
+ - lib/micro_micro/parsers/embedded_markup_property_parser.rb
89
+ - lib/micro_micro/parsers/implied_name_property_parser.rb
90
+ - lib/micro_micro/parsers/implied_photo_property_parser.rb
91
+ - lib/micro_micro/parsers/implied_url_property_parser.rb
92
+ - lib/micro_micro/parsers/plain_text_property_parser.rb
93
+ - lib/micro_micro/parsers/url_property_parser.rb
94
+ - lib/micro_micro/parsers/value_class_pattern_parser.rb
95
+ - lib/micro_micro/property.rb
96
+ - lib/micro_micro/relation.rb
97
+ - lib/micro_micro/version.rb
98
+ - lib/micromicro.rb
99
+ - micromicro.gemspec
100
+ homepage: https://github.com/jgarber623/micromicro
101
+ licenses:
102
+ - MIT
103
+ metadata:
104
+ bug_tracker_uri: https://github.com/jgarber623/micromicro/issues
105
+ changelog_uri: https://github.com/jgarber623/micromicro/blob/v0.1.0/CHANGELOG.md
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '2.5'
115
+ - - "<"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.8'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.1.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Extract microformats2-encoded data from HTML documents.
128
+ test_files: []