micromicro 2.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,31 +4,41 @@ module MicroMicro
4
4
  class Relationship
5
5
  include Collectible
6
6
 
7
+ # Extract {MicroMicro::Relationship}s from a context.
8
+ #
7
9
  # @param context [Nokogiri::HTML::Document, Nokogiri::XML::Element]
8
10
  # @return [Array<MicroMicro::Relationship>]
9
- def self.relationships_from(context)
11
+ def self.from_context(context)
10
12
  context.css('[href][rel]:not([rel=""])')
11
13
  .reject { |node| Helpers.ignore_nodes?(node.ancestors) }
12
14
  .map { |node| new(node) }
13
15
  end
14
16
 
17
+ # Parse a node for relationship data.
18
+ #
15
19
  # @param node [Nokogiri::XML::Element]
20
+ # @return [MicroMicro::Relationship]
16
21
  def initialize(node)
17
22
  @node = node
18
23
  end
19
24
 
25
+ # The value of the node's +href+ attribute.
26
+ #
20
27
  # @return [String]
21
28
  def href
22
29
  @href ||= node['href']
23
30
  end
24
31
 
32
+ # The value of the node's +hreflang+ attribute, if present.
33
+ #
25
34
  # @return [String, nil]
26
35
  def hreflang
27
36
  @hreflang ||= node['hreflang']&.strip
28
37
  end
29
38
 
30
- # :nocov:
31
39
  # @return [String]
40
+ #
41
+ # :nocov:
32
42
  def inspect
33
43
  "#<#{self.class}:#{format('%#0x', object_id)} " \
34
44
  "href: #{href.inspect}, " \
@@ -36,11 +46,15 @@ module MicroMicro
36
46
  end
37
47
  # :nocov:
38
48
 
49
+ # The value of the node's +media+ attribute, if present.
50
+ #
39
51
  # @return [String, nil]
40
52
  def media
41
53
  @media ||= node['media']&.strip
42
54
  end
43
55
 
56
+ # Return the parsed {MicroMicro::Relationship} as a Hash.
57
+ #
44
58
  # @return [Hash{Symbol => String}]
45
59
  def to_h
46
60
  {
@@ -51,24 +65,32 @@ module MicroMicro
51
65
  title: title,
52
66
  type: type,
53
67
  text: text
54
- }.select { |_, value| value.present? }
68
+ }.compact_blank!
55
69
  end
56
70
 
71
+ # An Array of unique values from node's +rel+ attribute.
72
+ #
57
73
  # @return [Array<String>]
58
74
  def rels
59
75
  @rels ||= node['rel'].split.uniq.sort
60
76
  end
61
77
 
78
+ # The node's text content.
79
+ #
62
80
  # @return [String]
63
81
  def text
64
82
  @text ||= node.text
65
83
  end
66
84
 
85
+ # The value of the node's +title+ attribute, if present.
86
+ #
67
87
  # @return [String, nil]
68
88
  def title
69
89
  @title ||= node['title']&.strip
70
90
  end
71
91
 
92
+ # The value of the node's +type+ attribute, if present.
93
+ #
72
94
  # @return [String, nil]
73
95
  def type
74
96
  @type ||= node['type']&.strip
@@ -76,6 +98,7 @@ module MicroMicro
76
98
 
77
99
  private
78
100
 
101
+ # @return [Nokogiri::XML::Element]
79
102
  attr_reader :node
80
103
  end
81
104
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MicroMicro
4
- VERSION = '2.0.1'
4
+ VERSION = '3.1.0'
5
5
  end
data/lib/micromicro.rb CHANGED
@@ -3,9 +3,9 @@
3
3
  require 'forwardable'
4
4
 
5
5
  require 'active_support/core_ext/array/grouping'
6
+ require 'active_support/core_ext/enumerable'
6
7
  require 'active_support/core_ext/hash/deep_transform_values'
7
- require 'active_support/core_ext/hash/keys'
8
- require 'active_support/core_ext/hash/slice'
8
+ require 'active_support/core_ext/hash/except'
9
9
  require 'active_support/core_ext/object/blank'
10
10
  require 'nokogiri'
11
11
  require 'nokogiri/html-ext'
@@ -15,6 +15,7 @@ require_relative 'micro_micro/collectible'
15
15
  require_relative 'micro_micro/helpers'
16
16
 
17
17
  require_relative 'micro_micro/parsers/date_time_parser'
18
+ require_relative 'micro_micro/parsers/image_element_parser'
18
19
  require_relative 'micro_micro/parsers/value_class_pattern_parser'
19
20
 
20
21
  require_relative 'micro_micro/parsers/base_property_parser'
@@ -41,13 +42,14 @@ require_relative 'micro_micro/collections/relationships_collection'
41
42
 
42
43
  module MicroMicro
43
44
  # Parse a string of HTML for microformats2-encoded data.
44
- # Convenience method for MicroMicro::Document.new.
45
45
  #
46
+ # Convenience method for {MicroMicro::Document#initialize}.
47
+ #
48
+ # @example
46
49
  # MicroMicro.parse('<a href="/" class="h-card" rel="me">Jason Garber</a>', 'https://sixtwothree.org')
47
50
  #
48
- # @param markup [String] The HTML to parse for microformats2-encoded data.
49
- # @param base_url [String] The URL associated with markup. Used for relative URL resolution.
50
- # @return [MicroMicro::Document]
51
+ # @param (see MicroMicro::Document#initialize)
52
+ # @return (see MicroMicro::Document#initialize)
51
53
  def self.parse(markup, base_url)
52
54
  Document.new(markup, base_url)
53
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micromicro
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-21 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -77,6 +77,7 @@ files:
77
77
  - lib/micro_micro/parsers/date_time_parser.rb
78
78
  - lib/micro_micro/parsers/date_time_property_parser.rb
79
79
  - lib/micro_micro/parsers/embedded_markup_property_parser.rb
80
+ - lib/micro_micro/parsers/image_element_parser.rb
80
81
  - lib/micro_micro/parsers/implied_name_property_parser.rb
81
82
  - lib/micro_micro/parsers/implied_photo_property_parser.rb
82
83
  - lib/micro_micro/parsers/implied_url_property_parser.rb
@@ -93,7 +94,7 @@ licenses:
93
94
  - MIT
94
95
  metadata:
95
96
  bug_tracker_uri: https://github.com/jgarber623/micromicro/issues
96
- changelog_uri: https://github.com/jgarber623/micromicro/blob/v2.0.1/CHANGELOG.md
97
+ changelog_uri: https://github.com/jgarber623/micromicro/blob/v3.1.0/CHANGELOG.md
97
98
  rubygems_mfa_required: 'true'
98
99
  post_install_message:
99
100
  rdoc_options: []