coelacanth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b51ba18dce6ea95e76c1fc67b267da6c2b8a688c5e40b402f68e2b688175485e
4
+ data.tar.gz: 01cd7b7e605ac2524e581d5b97bd3367047a314f0337baec028eb8a4d6897615
5
+ SHA512:
6
+ metadata.gz: a568228270b45bb3e4ffa7da6889f44d232b10bdafbe6fd63c11a9fc65ca399feeeb56cdc2120a8ed680bcdf3f43c0df2ddae3af7c05093ad9a0468ff30e66f8
7
+ data.tar.gz: b9bcff90f51c0186a6bc419fd36d70657a2ac1df8d6cbd090bd9c13106031e250c7744fdc442021232fddbb58fcf4b48759e5f2ffa0334f21479c547158c0521
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.3
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - 'spec/**/*'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-08-24
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at yusuke@slidict.io. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Dockerfile ADDED
@@ -0,0 +1,11 @@
1
+ FROM slidict/docker-rails:latest
2
+
3
+ ARG UID
4
+
5
+ RUN if [ "$UID" -ne "" ] ; then \
6
+ useradd user -d /app -u $UID; \
7
+ fi
8
+
9
+ RUN apt-get update -qq && apt-get install -y git
10
+ COPY . .
11
+ RUN bundle install
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in coelacanth.gemspec
6
+ gemspec
7
+
8
+ gem "ferrum", "~> 0.15"
9
+ gem "rake", "~> 13.0"
10
+ gem "rspec", "~> 3.0"
11
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ coelacanth (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.8.7)
10
+ public_suffix (>= 2.0.2, < 7.0)
11
+ ast (2.4.2)
12
+ concurrent-ruby (1.3.4)
13
+ diff-lcs (1.4.4)
14
+ ferrum (0.15)
15
+ addressable (~> 2.5)
16
+ concurrent-ruby (~> 1.1)
17
+ webrick (~> 1.7)
18
+ websocket-driver (~> 0.7)
19
+ json (2.7.1)
20
+ language_server-protocol (3.17.0.3)
21
+ parallel (1.24.0)
22
+ parser (3.3.0.5)
23
+ ast (~> 2.4.1)
24
+ racc
25
+ public_suffix (6.0.1)
26
+ racc (1.7.3)
27
+ rainbow (3.1.1)
28
+ rake (13.1.0)
29
+ regexp_parser (2.9.0)
30
+ rexml (3.2.6)
31
+ rspec (3.10.0)
32
+ rspec-core (~> 3.10.0)
33
+ rspec-expectations (~> 3.10.0)
34
+ rspec-mocks (~> 3.10.0)
35
+ rspec-core (3.10.1)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-expectations (3.10.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-mocks (3.10.2)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-support (3.10.2)
44
+ rubocop (1.62.1)
45
+ json (~> 2.3)
46
+ language_server-protocol (>= 3.17.0)
47
+ parallel (~> 1.10)
48
+ parser (>= 3.3.0.2)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml (>= 3.2.5, < 4.0)
52
+ rubocop-ast (>= 1.31.1, < 2.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 2.4.0, < 3.0)
55
+ rubocop-ast (1.31.2)
56
+ parser (>= 3.3.0.4)
57
+ ruby-progressbar (1.13.0)
58
+ unicode-display_width (2.5.0)
59
+ webrick (1.8.1)
60
+ websocket-driver (0.7.6)
61
+ websocket-extensions (>= 0.1.0)
62
+ websocket-extensions (0.1.5)
63
+
64
+ PLATFORMS
65
+ ruby
66
+ x86_64-linux
67
+
68
+ DEPENDENCIES
69
+ coelacanth!
70
+ ferrum (~> 0.15)
71
+ rake (~> 13.0)
72
+ rspec (~> 3.0)
73
+ rubocop (~> 1.21)
74
+
75
+ BUNDLED WITH
76
+ 2.5.14
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 yusuke abe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # coelacanth
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/coelacanth.svg)](https://badge.fury.io/rb/coelacanth)
4
+ [![Build Status](https://github.com/slidict/coelacanth/actions/workflows/test.yml/badge.svg)](https://github.com/slidict/coelacanth/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/123abc456def/maintainability)](https://codeclimate.com/github/slidict/coelacanth/maintainability)
7
+
8
+ `coelacanth` is a gem that allows you to parse and analyze web pages, extracting key statistics and information for further use within your projects.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+
15
+ ```ruby
16
+ gem 'coelacanth'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```bash
22
+ $ bundle install
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```bash
28
+ $ gem install coelacanth
29
+ ```
30
+
31
+ ### Resolving UID Mismatch Between Docker and Host
32
+
33
+ To resolve issues related to the difference between Docker's UID and the host's UID, add the following line to your .bashrc or similar shell configuration file:
34
+
35
+ ```bash
36
+ export UID=${UID}
37
+ ```
38
+
39
+ This will ensure that the environment variable UID is correctly set in your Docker containers, matching your host system's user ID.
40
+
41
+ This explanation provides clear instructions on how to resolve the UID mismatch issue using the export command.
42
+
43
+ ## Usage
44
+ To use coelacanth, first require it.
45
+
46
+ ```ruby
47
+ require 'coelacanth'
48
+ ```
49
+
50
+ Then, you can easily parse and extract information from a web page like this:
51
+
52
+ ```ruby
53
+ url = "https://example.com"
54
+ stats = Coelacanth.analyze(url)
55
+ ```
56
+
57
+ ## Features
58
+ - More features coming soon!
59
+
60
+ ## Contributing
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/slidict/coelacanth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
62
+
63
+ ## License
64
+ The gem is available as open-source under the terms of the MIT License.
65
+
66
+ ## Acknowledgments
67
+ Special thanks to all the contributors and open-source projects that make this possible.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,29 @@
1
+ changelog_type: 'commit_message' # or 'pull_request'
2
+ header_prefix: 'Version:'
3
+ commit_changelog: true
4
+ comment_changelog: true
5
+ include_unlabeled_changes: true
6
+ unlabeled_group_title: 'Unlabeled Changes'
7
+ pull_request_title_regex: '^Release'
8
+ version_regex: 'v?([0-9]{1,2})+[.]+([0-9]{1,2})+[.]+([0-9]{1,2})\s\(\d{1,2}-\d{1,2}-\d{4}\)'
9
+ exclude_labels:
10
+ - bot
11
+ - dependabot
12
+ - ci
13
+ group_config:
14
+ - title: Bug Fixes
15
+ labels:
16
+ - bug
17
+ - bugfix
18
+ - title: Code Improvements
19
+ labels:
20
+ - improvements
21
+ - enhancement
22
+ - title: New Features
23
+ labels:
24
+ - feature
25
+ - title: Documentation Updates
26
+ labels:
27
+ - docs
28
+ - documentation
29
+ - doc
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/coelacanth/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "coelacanth"
7
+ spec.version = Coelacanth::VERSION
8
+ spec.authors = ["Yusuke"]
9
+ spec.email = ["yusuke@slidict.io"]
10
+
11
+ spec.summary = "A gem for analyzing and extracting statistics from web pages."
12
+ spec.description = <<~DESC
13
+ coelacanth is a gem that allows you to easily parse and analyze web pages,
14
+ extracting key statistics and information for further use in various projects."
15
+ DESC
16
+ spec.homepage = "https://github.com/slidict/coelacanth"
17
+ spec.license = "MIT"
18
+ spec.required_ruby_version = ">= 3.3"
19
+
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/slidict/coelacanth"
23
+ spec.metadata["changelog_uri"] = "https://github.com/slidict/coelacanth/blob/main/CHANGELOG.md"
24
+
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
28
+ end
29
+ end
30
+
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # spec.add_dependency "nokogiri", "~> 1.12"
37
+ end
data/compose.yml ADDED
@@ -0,0 +1,23 @@
1
+ networks:
2
+ app-tier:
3
+ driver: bridge
4
+ services:
5
+ app:
6
+ environment:
7
+ - UID=${UID}
8
+ tty: true
9
+ stdin_open: true
10
+ build:
11
+ context: .
12
+ dockerfile: Dockerfile
13
+ volumes:
14
+ - ./:/app:cached
15
+ working_dir: /app
16
+ command: bash
17
+ networks:
18
+ - app-tier
19
+ chrome:
20
+ image: browserless/chrome:latest
21
+ container_name: chrome
22
+ networks:
23
+ - app-tier
@@ -0,0 +1,6 @@
1
+ development: &development
2
+ use_remote_client: false
3
+ test:
4
+ <<: *development
5
+ production:
6
+ <<: *development
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+ require "ferrum"
3
+
4
+ module Coelacanth
5
+ # Coelacanth::Client
6
+ class Client
7
+ def valid_url?(url)
8
+ uri = URI.parse(url)
9
+ uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
10
+ rescue URI::InvalidURIError
11
+ false
12
+ end
13
+
14
+ def resolve_redirect(url, limit = 10)
15
+ raise Coelacanth::DeepRedirectError, "Too many redirect" if limit.zero?
16
+ raise Coelacanth::RedirectError, "Url or location is nil" if url.nil?
17
+
18
+ response = get_response(url)
19
+
20
+ case response
21
+ when Net::HTTPSuccess then URI.parse(url)
22
+ when Net::HTTPRedirection then resolve_redirect(response["location"], limit - 1)
23
+ else
24
+ raise Coelacanth::RedirectError
25
+ end
26
+ end
27
+
28
+ def get_response(url)
29
+ if Configure.new.read("use_remote_client")
30
+ remote_client.goto(url)
31
+ remote_client.body
32
+ else
33
+ Net::HTTP.get_response(URI.parse(url))
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def remote_client
40
+ @remote_client ||= Ferrum::Browser.new(
41
+ ws_url: "ws://chrome:3000/chrome",
42
+ timeout: 20
43
+ ).create_page
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ require "yaml"
3
+ require "erb"
4
+
5
+ module Coelacanth
6
+ # Coelacanth::Configure
7
+ class Configure
8
+ CONFIG_PATH = "config/coelacanth.yml"
9
+
10
+ def read(key)
11
+ @yaml ||= YAML.unsafe_load(ERB.new(File.read(file)).result)[env]
12
+ @yaml[key]
13
+ end
14
+
15
+ private
16
+
17
+ def root
18
+ return ::Rails.root if defined?(::Rails)
19
+
20
+ Pathname.new(File.expand_path("../..", __dir__))
21
+ end
22
+
23
+ def file
24
+ root.join(CONFIG_PATH)
25
+ end
26
+
27
+ def env
28
+ return ::Rails.env if defined?(::Rails)
29
+
30
+ env_value = ENV["RAILS_ENV"].to_s.strip
31
+ env_value = ENV["RACK_ENV"].to_s.strip if env_value.empty?
32
+ env_value.empty? ? "development" : env_value
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coelacanth
4
+ VERSION = "0.1.0"
5
+ end
data/lib/coelacanth.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require_relative "coelacanth/version"
5
+ require_relative "coelacanth/configure"
6
+ require_relative "coelacanth/client"
7
+
8
+ # Coelacanth
9
+ module Coelacanth
10
+ class Error < StandardError; end
11
+ class RedirectError < StandardError; end
12
+ class DeepRedirectError < StandardError; end
13
+
14
+ def self.analyze(_url)
15
+ {
16
+ todo: "implement me"
17
+ }
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coelacanth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ coelacanth is a gem that allows you to easily parse and analyze web pages,
15
+ extracting key statistics and information for further use in various projects."
16
+ email:
17
+ - yusuke@slidict.io
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - CHANGELOG.md
25
+ - CODE_OF_CONDUCT.md
26
+ - Dockerfile
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - changelog-ci-config.yml
33
+ - coelacanth.gemspec
34
+ - compose.yml
35
+ - config/coelacanth.yml
36
+ - lib/coelacanth.rb
37
+ - lib/coelacanth/client.rb
38
+ - lib/coelacanth/configure.rb
39
+ - lib/coelacanth/version.rb
40
+ homepage: https://github.com/slidict/coelacanth
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ allowed_push_host: https://rubygems.org
45
+ homepage_uri: https://github.com/slidict/coelacanth
46
+ source_code_uri: https://github.com/slidict/coelacanth
47
+ changelog_uri: https://github.com/slidict/coelacanth/blob/main/CHANGELOG.md
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '3.3'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.5.7
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A gem for analyzing and extracting statistics from web pages.
67
+ test_files: []