tagfinder 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: f87a741afdd4db26c24bda9112839c25f98e9be39afa108f567f7d4e264825c0
4
+ data.tar.gz: 8b4f86f087503f46ed11f11d0dfae6a7eba729134824c47a1ad7986416c44771
5
+ SHA512:
6
+ metadata.gz: 2556c76e38282ac11b489f8591635579445897679bbda862e8efe167667e7eb11f86aa7549a5f0ea434f6c5a4e450566e2ffe16258df5fe5e9845e709458d8ac
7
+ data.tar.gz: 7d03e047a729525a7f3e8f565f0649f331d5d755179a4f1dfdcab1eebf1ae08500317312f33cc917d574f93bc70b41776bcb38d1ed272a063aecd5848cbbcaca
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "tagfinder"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/tagfinder ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'tagfinder'
3
+ Tagfinder::CLI.start(ARGV)
data/lib/tagfinder.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "tagfinder/version"
4
+ require_relative "tagfinder/commands/command"
5
+ require_relative "tagfinder/commands/find"
6
+ require "thor"
7
+
8
+ module Tagfinder
9
+ class Error < StandardError; end
10
+
11
+ class CLI < Thor
12
+ def self.exit_on_failure?
13
+ true
14
+ end
15
+
16
+ desc "find", "Search for text in an url"
17
+ def find(url, text)
18
+ find_command = Find.new(url, text)
19
+ find_command.execute()
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ class Command
2
+ def execute
3
+ raise NotImplementedError
4
+ end
5
+
6
+ def unexecute
7
+ raise NotImplementedError
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../parser'
2
+
3
+ class Find < Command
4
+ def initialize(url, text)
5
+ @url = url
6
+ @text = text
7
+ end
8
+
9
+ def execute
10
+ puts "Searching for #{@text} on the url #{@url}..."
11
+ parser = Parser.new(@url)
12
+ result = parser.find_text_in_document(@text)
13
+ if !result.nil?
14
+ puts result
15
+ else
16
+ puts "No text found."
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ require 'mechanize'
2
+
3
+ class Parser
4
+ def initialize(url)
5
+ @url = url
6
+ end
7
+
8
+ def find_text_in_document(text)
9
+ agent = Mechanize.new
10
+ page = agent.get(@url)
11
+ result = page.search(":contains('#{text}'):not(:has(:contains('#{text}')))")
12
+ if !result.to_s.empty?
13
+ return result
14
+ end
15
+ return nil
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tagfinder
4
+ VERSION = "0.1.1"
5
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tagfinder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Guilherme Eric
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
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: mechanize
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
+ description:
42
+ email:
43
+ - guilherme.eric@outlook.com
44
+ executables:
45
+ - tagfinder
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - bin/console
50
+ - bin/setup
51
+ - exe/tagfinder
52
+ - lib/tagfinder.rb
53
+ - lib/tagfinder/commands/command.rb
54
+ - lib/tagfinder/commands/find.rb
55
+ - lib/tagfinder/parser.rb
56
+ - lib/tagfinder/version.rb
57
+ homepage: https://github.com/guilhermeeric/tagfinder
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://github.com/guilhermeeric/tagfinder
62
+ source_code_uri: https://github.com/guilhermeeric/tagfinder
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.4.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Search an HTML document for a text and return the tags enclosing it.
82
+ test_files: []