mecha_browser 0.1.0

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: 67e13c41a2da13f35d3a8a41e5292ad105831b7e5eebddccd2d68d03651f3c6d
4
+ data.tar.gz: 7214c0e4f92828641c86ae55ec3758287c8040fafd8c5776811e8bf6a7a46545
5
+ SHA512:
6
+ metadata.gz: ac139a0d3fa2d947c962b0f44700770d3ba58e48447828c4dd3f11a89ff6dedab333ff0931e53c5bb13e3d456647e3fffa2f54a79ba4172a3c2194a28f6c95e5
7
+ data.tar.gz: 4c9f488f0310a494cc29a261d81d8a6378194fd5c779da660fa24a24781c4a9a2bc475e1e24a997ddfb21b9a660cbb5b005d88e5321914d488b5f97fcc878625
@@ -0,0 +1,8 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(rake test)"
5
+ ],
6
+ "deny": []
7
+ }
8
+ }
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # デフォルトの無視対象ファイル
2
+ /shelf/
3
+ /workspace.xml
4
+ # エディターベースの HTTP クライアントリクエスト
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
@@ -0,0 +1,48 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="GemInspection" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ <inspection_tool class="RbsBadTypeArgumentType" enabled="false" level="ERROR" enabled_by_default="false" />
6
+ <inspection_tool class="RbsBadTypeVariableDefaultType" enabled="false" level="ERROR" enabled_by_default="false" />
7
+ <inspection_tool class="RbsConflictingTypeVariableCount" enabled="false" level="ERROR" enabled_by_default="false" />
8
+ <inspection_tool class="RbsConflictingTypeVariableVariance" enabled="false" level="ERROR" enabled_by_default="false" />
9
+ <inspection_tool class="RbsCyclicClassModuleAliasDeclaration" enabled="false" level="ERROR" enabled_by_default="false" />
10
+ <inspection_tool class="RbsDuplicateDeclarations" enabled="false" level="ERROR" enabled_by_default="false" />
11
+ <inspection_tool class="RbsDuplicateKeywordParameter" enabled="false" level="WARNING" enabled_by_default="false" />
12
+ <inspection_tool class="RbsInconsistentClassModuleAlias" enabled="false" level="ERROR" enabled_by_default="false" />
13
+ <inspection_tool class="RbsIncorrectInclusionCall" enabled="false" level="ERROR" enabled_by_default="false" />
14
+ <inspection_tool class="RbsIncorrectTypeArgumentCount" enabled="false" level="ERROR" enabled_by_default="false" />
15
+ <inspection_tool class="RbsIncorrectTypeArgumentVariance" enabled="false" level="ERROR" enabled_by_default="false" />
16
+ <inspection_tool class="RbsInvalidMethodOverload" enabled="false" level="ERROR" enabled_by_default="false" />
17
+ <inspection_tool class="RbsInvalidTypeArgumentUsage" enabled="false" level="ERROR" enabled_by_default="false" />
18
+ <inspection_tool class="RbsLiteralClassReferenced" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
19
+ <inspection_tool class="RbsMissingTypeSignature" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
20
+ <inspection_tool class="RbsModuleUsedAsSuperclass" enabled="false" level="ERROR" enabled_by_default="false" />
21
+ <inspection_tool class="RbsSimplifiableBooleanUnion" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
22
+ <inspection_tool class="RbsUnconventionalInterfaceName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
23
+ <inspection_tool class="RbsUnconventionalTypeAliasName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
24
+ <inspection_tool class="RbsUnconventionalTypeVariableName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
25
+ <inspection_tool class="RbsUnconventionalUseAliasName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
26
+ <inspection_tool class="RbsUnnecessaryParentheses" enabled="false" level="INFORMATION" enabled_by_default="false" />
27
+ <inspection_tool class="RbsUnnecessaryQualifier" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
28
+ <inspection_tool class="RbsUnresolvedReference" enabled="false" level="ERROR" enabled_by_default="false" />
29
+ <inspection_tool class="RbsUnusedInterface" enabled="false" level="WARNING" enabled_by_default="false" />
30
+ <inspection_tool class="RbsUnusedTypeAlias" enabled="false" level="WARNING" enabled_by_default="false" />
31
+ <inspection_tool class="RbsUnusedTypeVariable" enabled="false" level="WARNING" enabled_by_default="false" />
32
+ <inspection_tool class="RbsUnusedUseClause" enabled="false" level="WARNING" enabled_by_default="false" />
33
+ <inspection_tool class="RubyCaseWithoutElseBlockInspection" enabled="false" level="WARNING" enabled_by_default="false" />
34
+ <inspection_tool class="RubyLiteralArrayInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
35
+ <inspection_tool class="RubyMismatchedArgumentType" enabled="false" level="WARNING" enabled_by_default="false" />
36
+ <inspection_tool class="RubyMismatchedReturnType" enabled="false" level="WARNING" enabled_by_default="false" />
37
+ <inspection_tool class="RubyMismatchedVariableType" enabled="false" level="WARNING" enabled_by_default="false" />
38
+ <inspection_tool class="RubyNilAnalysis" enabled="false" level="WARNING" enabled_by_default="false" />
39
+ <inspection_tool class="RubyUnnecessaryReturnStatement" enabled="false" level="WARNING" enabled_by_default="false" />
40
+ <inspection_tool class="RubyUnnecessaryReturnValue" enabled="false" level="WARNING" enabled_by_default="false" />
41
+ <inspection_tool class="RubyUnusedLocalVariable" enabled="false" level="WARNING" enabled_by_default="false" />
42
+ <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
43
+ <option name="processCode" value="true" />
44
+ <option name="processLiterals" value="true" />
45
+ <option name="processComments" value="true" />
46
+ </inspection_tool>
47
+ </profile>
48
+ </component>
@@ -0,0 +1,130 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ <excludeFolder url="file://$MODULE_DIR$/vendor/bundle" />
12
+ </content>
13
+ <orderEntry type="jdk" jdkName="rbenv: 3.2.6" jdkType="RUBY_SDK" />
14
+ <orderEntry type="sourceFolder" forTests="false" />
15
+ <orderEntry type="module-library">
16
+ <library name="minitest (v5.25.5) [path][gem]" type="rubylib">
17
+ <properties>
18
+ <option name="additionalInfo">
19
+ <AdditionalInfo>
20
+ <option name="authors" value="該当なし" />
21
+ <option name="email" value="該当なし" />
22
+ <option name="homepage" value="該当なし" />
23
+ <option name="summary" value="該当なし" />
24
+ </AdditionalInfo>
25
+ </option>
26
+ <option name="fromPath" value="true" />
27
+ <option name="name" value="minitest" />
28
+ <option name="requirePaths">
29
+ <list>
30
+ <option value="lib" />
31
+ </list>
32
+ </option>
33
+ <option name="url" value="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5" />
34
+ <option name="version" value="5.25.5" />
35
+ </properties>
36
+ <CLASSES>
37
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5/lib" />
38
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5/test" />
39
+ </CLASSES>
40
+ <JAVADOC />
41
+ <SOURCES>
42
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5/lib" />
43
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5/test" />
44
+ </SOURCES>
45
+ <excluded>
46
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5/test" />
47
+ </excluded>
48
+ </library>
49
+ </orderEntry>
50
+ <orderEntry type="module-library">
51
+ <library name="rake (v13.3.0) [path][gem]" type="rubylib">
52
+ <properties>
53
+ <option name="additionalInfo">
54
+ <AdditionalInfo>
55
+ <option name="authors" value="該当なし" />
56
+ <option name="email" value="該当なし" />
57
+ <option name="homepage" value="該当なし" />
58
+ <option name="summary" value="該当なし" />
59
+ </AdditionalInfo>
60
+ </option>
61
+ <option name="fromPath" value="true" />
62
+ <option name="name" value="rake" />
63
+ <option name="requirePaths">
64
+ <list>
65
+ <option value="lib" />
66
+ </list>
67
+ </option>
68
+ <option name="url" value="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.3.0" />
69
+ <option name="version" value="13.3.0" />
70
+ </properties>
71
+ <CLASSES>
72
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.3.0/doc" />
73
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.3.0/exe" />
74
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.3.0/lib" />
75
+ </CLASSES>
76
+ <JAVADOC />
77
+ <SOURCES>
78
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.3.0/doc" />
79
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.3.0/exe" />
80
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.3.0/lib" />
81
+ </SOURCES>
82
+ <excluded>
83
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.3.0/doc" />
84
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.3.0/exe" />
85
+ </excluded>
86
+ </library>
87
+ </orderEntry>
88
+ <orderEntry type="module-library">
89
+ <library name="web_loader (v1.7.0) [path][gem]" type="rubylib">
90
+ <properties>
91
+ <option name="additionalInfo">
92
+ <AdditionalInfo>
93
+ <option name="authors" value="該当なし" />
94
+ <option name="email" value="該当なし" />
95
+ <option name="homepage" value="該当なし" />
96
+ <option name="summary" value="該当なし" />
97
+ </AdditionalInfo>
98
+ </option>
99
+ <option name="fromPath" value="true" />
100
+ <option name="name" value="web_loader" />
101
+ <option name="requirePaths">
102
+ <list>
103
+ <option value="lib" />
104
+ </list>
105
+ </option>
106
+ <option name="url" value="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0" />
107
+ <option name="version" value="1.7.0" />
108
+ </properties>
109
+ <CLASSES>
110
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0/exe" />
111
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0/lib" />
112
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0/sig" />
113
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0/.idea" />
114
+ </CLASSES>
115
+ <JAVADOC />
116
+ <SOURCES>
117
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0/exe" />
118
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0/lib" />
119
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0/sig" />
120
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0/.idea" />
121
+ </SOURCES>
122
+ <excluded>
123
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0/exe" />
124
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/web_loader-1.7.0/.idea" />
125
+ </excluded>
126
+ </library>
127
+ </orderEntry>
128
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.4.19, rbenv: 3.2.6) [gem]" level="application" />
129
+ </component>
130
+ </module>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/mecha_browser.iml" filepath="$PROJECT_DIR$/.idea/mecha_browser.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-07-04
4
+
5
+ - Initial release
data/CLAUDE.md ADDED
@@ -0,0 +1,67 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ やりとりは日本語でお願いします。
6
+
7
+ ## 開発コマンド
8
+
9
+ ### 基本的な開発コマンド
10
+ - `rake test` - テストの実行
11
+ - `bin/console` - 対話的なコンソールでのテスト
12
+ - `bundle exec rake install` - ローカルマシンにgemをインストール
13
+ - `bundle exec rake release` - バージョンをリリース
14
+
15
+ ### 実行ファイル
16
+ - `exe/mb` - メインの実行ファイル(MechaBrowser::Command.run(ARGV)を呼び出す)
17
+
18
+ ## プロジェクト構造
19
+
20
+ ### アーキテクチャ概要
21
+ MechaBrowserは、プログラムでWebブラウジングを行うためのRuby gemです。異なるブラウザバックエンドを選択できるプラグイン型のアーキテクチャを採用しています。
22
+
23
+ ### 主要コンポーネント
24
+ 1. **Command Layer** (`lib/mecha_browser/command.rb`)
25
+ - コマンドライン引数の解析
26
+ - 設定ファイルの読み込み(`~/.mechabrowser`)
27
+ - ブラウザタイプの選択(ruby/selenium)
28
+ - オプション:`-v`(verbose)、`-n`(dry-run)、`-c`(config)、`-t`(type)
29
+
30
+ 2. **Browser Layer** (`lib/mecha_browser/browser/`)
31
+ - `BaseBrowser` - すべてのブラウザ実装のベースクラス
32
+ - `RubyBrowser` - web_loadergemを使用したRuby実装
33
+ - User Agent、ログ、verboseモードの設定をサポート
34
+
35
+ 3. **Configuration**
36
+ - YAMLベースの設定ファイル
37
+ - User Agentのカスタマイズ
38
+ - デフォルト値の自動設定
39
+
40
+ ### 重要な依存関係
41
+ - `web_loader` - RubyBrowserで使用するWebコンテンツ読み込み用gem
42
+ - `minitest` - テストフレームワーク
43
+
44
+ ### 設定ファイル
45
+ - デフォルト設定ファイル:`~/.mechabrowser`
46
+ - YAML形式で`browser.user_agent`等の設定が可能
47
+ - 設定されていない場合は、デフォルトのUser Agentを使用
48
+
49
+ ## 開発における重要なポイント
50
+
51
+ ### ブラウザタイプの拡張
52
+ 新しいブラウザタイプを追加する場合:
53
+ 1. `lib/mecha_browser/browser/`に新しいクラスを作成
54
+ 2. `BaseBrowser`を継承
55
+ 3. `browse(url)`メソッドを実装
56
+ 4. `command.rb`の`create_browser`メソッドにケースを追加
57
+
58
+ ### テスト
59
+ - `rake test`でテストを実行
60
+ - テストファイルは`test/test_*.rb`の形式
61
+ - 現在のテストは未完成(`assert false`のままのテストあり)
62
+
63
+ # important-instruction-reminders
64
+ Do what has been asked; nothing more, nothing less.
65
+ NEVER create files unless they're absolutely necessary for achieving your goal.
66
+ ALWAYS prefer editing an existing file to creating a new one.
67
+ NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
@@ -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 src@srcw.net. 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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 src
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,105 @@
1
+ # MechaBrowser
2
+
3
+ Mecha Browser is a Ruby gem that allows users to browse the web programmatically, automating interactions with web pages and extracting information in a mechanical fashion.
4
+
5
+ ## インストール
6
+
7
+ Gemfileに以下の行を追加してください:
8
+
9
+ ```ruby
10
+ gem 'mecha_browser'
11
+ ```
12
+
13
+ そして以下を実行してください:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ またはgemコマンドでインストールできます:
20
+
21
+ ```bash
22
+ $ gem install mecha_browser
23
+ ```
24
+
25
+ ## 使い方
26
+
27
+ ### コマンドライン
28
+
29
+ ```bash
30
+ $ mb [オプション] <URL>
31
+ ```
32
+
33
+ ### オプション
34
+
35
+ - `-v, --verbose`: 詳細なメッセージを表示
36
+ - `-n, --dry-run`: メッセージのみを表示(実際のアクセスなし)
37
+ - `-d, --config-dir`: 設定ディレクトリを指定
38
+ - `-t, --type`: ブラウザタイプを指定(ruby|selenium、デフォルト:ruby)
39
+ - `-h, --help`: ヘルプメッセージを表示
40
+
41
+ ### 例
42
+
43
+ ```bash
44
+ # 基本的な使用
45
+ $ mb https://example.com
46
+
47
+ # 詳細モードで実行
48
+ $ mb -v https://example.com
49
+
50
+ # ドライランモード
51
+ $ mb -n https://example.com
52
+ ```
53
+
54
+ ### 設定ファイル
55
+
56
+ デフォルトの設定ファイルは `~/.mechabrowser/config.yml` です。
57
+
58
+ 設定例:
59
+
60
+ ```yaml
61
+ browser:
62
+ user_agent: "User Agent String"
63
+ ```
64
+
65
+ ## 開発
66
+
67
+ ### 基本的な開発コマンド
68
+
69
+ ```bash
70
+ # テストの実行
71
+ $ rake test
72
+
73
+ # 対話的なコンソールでのテスト
74
+ $ bin/console
75
+
76
+ # ローカルマシンにgemをインストール
77
+ $ bundle exec rake install
78
+
79
+ # リリース
80
+ $ bundle exec rake release
81
+ ```
82
+
83
+ ### アーキテクチャ
84
+
85
+ MechaBrowserはプラグイン型のアーキテクチャを採用しており、異なるブラウザバックエンドを選択できます。
86
+
87
+ #### 主要コンポーネント
88
+
89
+ 1. **Command Layer** - コマンドライン引数の解析と設定管理
90
+ 2. **Browser Layer** - ブラウザ実装の抽象化
91
+ - `BaseBrowser` - すべてのブラウザ実装のベースクラス
92
+ - `RubyBrowser` - web_loadergemを使用したRuby実装
93
+
94
+ #### 依存関係
95
+
96
+ - `web_loader` - RubyBrowserで使用するWebコンテンツ読み込み用gem
97
+ - `minitest` - テストフレームワーク
98
+
99
+ ## ライセンス
100
+
101
+ MIT License
102
+
103
+ ## 貢献
104
+
105
+ バグレポートやプルリクエストは歓迎します。このプロジェクトは、協力的で歓迎されるコミュニティを提供することを目的としています。
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ task default: :test
data/build.sh ADDED
@@ -0,0 +1,27 @@
1
+ #!/bin/sh
2
+ # rmagick for sierra
3
+ #export PKG_CONFIG_PATH=/usr/local/opt/imagemagick@6/lib/pkgconfig
4
+ #export PATH=/usr/local/Cellar/imagemagick@6/6.9.7-5/bin:$PATH
5
+
6
+ bundle_dir=./vendor/bundle
7
+ bundle config --local path $bundle_dir
8
+
9
+ if [ "$1" = "clean" ]; then
10
+ echo "rm -rf $bundle_dir"
11
+ /bin/rm -rf "$bundle_dir"
12
+ /bin/rm Gemfile.lock
13
+ exit 0
14
+ fi
15
+
16
+ if [ -d "$bundle_dir" ] ; then
17
+ echo "bunlde update"
18
+ bundle update
19
+ bundle clean
20
+ else
21
+ echo "bundle install"
22
+ /bin/rm -rf "$bundle_dir"
23
+ bundle install
24
+ fi
25
+
26
+
27
+
data/exe/mb ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "mecha_browser"
4
+
5
+ MechaBrowser::Command.run(ARGV)
@@ -0,0 +1,28 @@
1
+ module MechaBrowser
2
+ module Browser
3
+ class BaseBrowser
4
+ def initialize
5
+ @user_agent = nil
6
+ @verbose = false
7
+ @logger = nil
8
+ end
9
+ attr_accessor :user_agent
10
+ attr_accessor :verbose
11
+ attr_accessor :logger
12
+
13
+ def browse(url)
14
+ raise NotImplementedError, "Subclasses must implement the run method"
15
+ end
16
+
17
+ private
18
+ def log(msg, put_log = @verbose)
19
+ return unless put_log
20
+ if @logger
21
+ @logger.info(msg)
22
+ else
23
+ puts msg
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ require "web_loader"
2
+
3
+ module MechaBrowser
4
+ module Browser
5
+ class RubyBrowser < BaseBrowser
6
+ def initialize
7
+ end
8
+
9
+ def browse(url)
10
+ log("RubyBrowser : #{url} #{@user_agent} #{@verbose}")
11
+
12
+ loader = ::WebLoader::Command.new
13
+ loader.user_agent = @user_agent
14
+ loader.verbose = @verbose
15
+ loader.logger = @logger
16
+ loader.use_cache = false
17
+ result = loader.load(url)
18
+ result
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,119 @@
1
+ require "optparse"
2
+
3
+ module MechaBrowser
4
+ USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
5
+ CONFIG_DIR = File.expand_path("~/.mechabrowser")
6
+
7
+ class Config
8
+ def self.load_config_file(config_file)
9
+ yaml = nil
10
+ if FileTest.file?(config_file)
11
+ yaml = YAML.load_file(config_file)
12
+ end
13
+ load_from_yaml(yaml)
14
+ end
15
+
16
+ def self.load_from_yaml(yaml)
17
+ config = Config.new
18
+ config.user_agent = config_value(yaml, "browser", "user_agent", false)
19
+ config.init_default
20
+ config
21
+ end
22
+
23
+ def self.config_value(yaml, section, key, require)
24
+ return nil unless yaml
25
+ return nil unless yaml[section]
26
+ value = yaml[section][key]
27
+ if require && (value.nil? || value.empty?)
28
+ raise RuntimeError, "#{section}:#{key}: is empty"
29
+ end
30
+ value
31
+ end
32
+
33
+ def initialize
34
+ super
35
+ end
36
+
37
+ def init_default
38
+ @user_agent ||= USER_AGENT
39
+ @config ||= CONFIG_DIR
40
+ end
41
+
42
+ attr_accessor :user_agent
43
+ attr_accessor :config_dir
44
+ end
45
+
46
+ class Command
47
+ def self.run(argv)
48
+ STDOUT.sync = true
49
+ opts = {}
50
+ opt = OptionParser.new(argv)
51
+ opt.banner = "Usage: #{opt.program_name} [-h|--help] <options> <url>"
52
+ opt.version = VERSION
53
+ opt.separator('')
54
+ opt.separator("Options:")
55
+ opt.on_head('-h', '--help', 'Show this message') do |v|
56
+ puts opt.help
57
+ exit
58
+ end
59
+ opt.on('-v', '--verbose', 'Verbose message') {|v| opts[:v] = v}
60
+ opt.on('-n', '--dry-run', 'Message only') {|v| opts[:n] = v}
61
+ opt.on('-d', '--config-dir', 'Config directory'){|v| opts[:d] = v }
62
+ types = ['ruby', 'selenium']
63
+ opt.on('-t', '--type', types, types.join("|") + "(default ruby)") {|v| opts[:t] = v}
64
+ opt.parse!(argv)
65
+ opts[:t] ||= types[0]
66
+
67
+ config_dir = opts[:d] || CONFIG_DIR
68
+ config_dir = File.expand_path(config_dir)
69
+ config_file = File.join(config_dir, "config.yml")
70
+
71
+ config = Config.load_config_file(config_file)
72
+ config.config_dir = config_dir
73
+ command = Command.new(opts, config)
74
+ command.run(argv)
75
+ # filepaths = self.filter_files(argv)
76
+ # if filepaths.empty?
77
+ # puts opt.help
78
+ # exit
79
+ # end
80
+ # filepaths.each do |filepath|
81
+ # command = Imagefilter.new(opts, config)
82
+ # command.run(filepath)
83
+ # end
84
+ end
85
+
86
+ def initialize(opts, config)
87
+ @opts = opts
88
+ @config = config
89
+ @verbose = opts[:v] || false
90
+ @dry_run = opts[:n] || false
91
+ @type = opts[:t] || 'ruby'
92
+ end
93
+
94
+ def run(argv)
95
+ url = argv.shift
96
+ browser = create_browser
97
+ result = browser.browse(url)
98
+ puts result.to_s
99
+ result
100
+ end
101
+
102
+ private
103
+ def create_browser
104
+ case @type
105
+ when 'ruby'
106
+ browser = MechaBrowser::Browser::RubyBrowser.new
107
+ # when 'selenium'
108
+ # require_relative 'browser/selenium_browser'
109
+ # browser = MechaBrowser::Browser::SeleniumBrowser.new
110
+ else
111
+ raise ArgumentError, "Unknown browser type: #{@type}"
112
+ end
113
+ browser.user_agent = @config.user_agent
114
+ browser.verbose = @verbose
115
+ browser.logger = @logger if @logger
116
+ browser
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MechaBrowser
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "mecha_browser/version"
4
+ require_relative "mecha_browser/command"
5
+ require_relative "mecha_browser/browser/base_browser"
6
+ require_relative "mecha_browser/browser/ruby_browser"
7
+
8
+ module MechaBrowser
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,4 @@
1
+ module MechaBrowser
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/test.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ #bundle exec rake test TEST=test/models/entry_test.rb TESTOPTS="--name=test_sample_2"
3
+ bundle exec rake test
4
+
data/test_mb.sh ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ bundle exec ruby exe/mb "$@"
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mecha_browser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - src
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: web_loader
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
+ description: Mecha Browser is a Ruby gem that allows users to browse the web programmatically,
28
+ automating interactions with web pages and extracting information in a mechanical
29
+ fashion.
30
+ email:
31
+ - src@srcw.net
32
+ executables:
33
+ - mb
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - ".claude/settings.local.json"
38
+ - ".idea/.gitignore"
39
+ - ".idea/inspectionProfiles/Project_Default.xml"
40
+ - ".idea/mecha_browser.iml"
41
+ - ".idea/modules.xml"
42
+ - ".idea/vcs.xml"
43
+ - CHANGELOG.md
44
+ - CLAUDE.md
45
+ - CODE_OF_CONDUCT.md
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - build.sh
50
+ - exe/mb
51
+ - lib/mecha_browser.rb
52
+ - lib/mecha_browser/browser/base_browser.rb
53
+ - lib/mecha_browser/browser/ruby_browser.rb
54
+ - lib/mecha_browser/command.rb
55
+ - lib/mecha_browser/version.rb
56
+ - sig/mecha_browser.rbs
57
+ - test.sh
58
+ - test_mb.sh
59
+ homepage: https://srcw.net
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ allowed_push_host: https://rubygems.org
64
+ homepage_uri: https://srcw.net
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 2.6.0
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.4.19
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Mecha Browser - A Ruby gem for browsing the web with a mechanical approach.
84
+ test_files: []