Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coop command #134

Merged
merged 1 commit into from
May 22, 2024
Merged

Add coop command #134

merged 1 commit into from
May 22, 2024

Conversation

fujiwara-e
Copy link
Contributor

概要

coop コマンドの追加

コマンドの概要

機能

岡山大学生協の営業中の店舗および営業時間を表示する.

使用方法

swimmy coop open もしくは swimmy coop timeと入力する.

特徴

岡山大学生協webサイトをスクレイピングし,取得したデータを整理し表示する.

@fujiwara-e
Copy link
Contributor Author

変更点

  • 改行数の削減
  • CoopInfoFormatterのメソッドを変更
  • 店舗が開いているかをcommand内で判定
  • ファイル名をスネークケースに変更

コードレビューで頂いたアドバイスを基に,コードを修正しました

@yoshinari-nomura
Copy link
Member

  • 無駄な改行が取れていないように思います
  • 引数や関数名に統一的なルールを課してください.
  • たとえば,get_shop_open(shopinfo) の引数が shpinfo というのは意味がよくわかりません.
  • shopinfo と coopinfo の違いはなんでしょう
  • get_shopinfo というメソッド名は ShopInfo を返すように思えるが実際には CoopInfo の 配列 を返しているの

@fujiwara-e fujiwara-e force-pushed the coop_cmd branch 3 times, most recently from 452a3ef to e5774f8 Compare May 13, 2024 02:35
@fujiwara-e
Copy link
Contributor Author

fujiwara-e commented May 13, 2024

変更点

  • 改行数の削減
  • インデントを4から2へ変更
  • CoopInfoFormatter -> ShopInfoFormatter
  • class CoopInfo -> class ShopInfo
  • gemfile に nokogiri を追加

いただいたコメントを基に,コードを修正しました

Copy link
Member

@yoshinari-nomura yoshinari-nomura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review コメントしました.

module Swimmy
module Command
class Coop < Swimmy::Command::Base
class ShopInfoFormatter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

現段階では class にまでしないで ShopInfo の to_s メソッドにするのがいいでしょう.

lib/swimmy/command/coop.rb Show resolved Hide resolved
end

def open?
if @state == "OPEN"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1行 @State == "OPEN" だけで十分です

end

def name
s = @f_name.chomp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chomp や strip は,initialize で代入するときにしておいたおうがいいです

@@ -0,0 +1,29 @@
module Swimmy
module Resource
class ShopInfo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ファイル名 coop_info と クラス名 ShopInfo が対応が取れていません.CoopShop でしょうか.

text.lines(chomp: true) do |char|
if d >4
shops << Swimmy::Resource::ShopInfo.new(f_name,shopdata[0],shopdata[1],shopdata[2],shopdata[3])
d = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d とは,何で 4とは何でしょう.i もよく分かりません.
shopdata のような配列を使うのではなくて,それぞれが名前を識別できるような個別の変数を用意して,それを埋めていくような構造にしたほうがいいです.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全体的に何をしようとしているのか理解し辛いです.
スクレイピングしようとしている HTML 全体がどういう構造になっているのかの概略や,
next_element を取り出す意味などをコメントで説明するといいです.

text.slice!(0)
text.lines(chomp: true) do |char|
if d >4
shops << Swimmy::Resource::ShopInfo.new(f_name,shopdata[0],shopdata[1],shopdata[2],shopdata[3])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コンマの後にはスペースを入れてください.

attr_accessor :f_name,:state,:n_name,:time,:ex

def initialize(f_name,state,n_name,time,ex)
@f_name, @state, @n_name ,@time ,@ex = f_name, state, n_name, time, ex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは,オプショナルですが,
time は,相手の文字列をそのまま使うのではなくて,2つの時刻(数値)に置き換えて保存したほうがいいでしょう.start_time, end_time のような.
そのほうが,フォーマッタや比較が楽になります.

end

def open?
if @state == "OPEN"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

オプショナルですが,本来は,OPEN かどうかは,時刻から判断すべきで,open?(aTime = Time.now) のようなインタフェースになると思います.

@fujiwara-e fujiwara-e force-pushed the coop_cmd branch 2 times, most recently from c313b6c to 672bb6e Compare May 17, 2024 01:15
@fujiwara-e
Copy link
Contributor Author

変更点

  • フォーマッタを to_s メソッドに変更
  • case 文内での重複を改善
  • initialize する際に chomp を行うように変更
  • class ShopInfo -> class CoopShop
  • accessor の削除,_ex は使用しないためスクレイピングで取得しないように変更
  • service のファイル名を coop.rb に変更
  • スクレイピングでのノードの探索方法を変更
  • time は start_time と end_time に分けてそれぞれ Time オブジェクトとして保存するように変更
  • open? を現在時刻から判定するように変更

いただいたコメントを基に,コードを修正しました

Copy link
Member

@yoshinari-nomura yoshinari-nomura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いいと思います.修正したら merge してもらってください.

lib/swimmy/command/coop.rb Outdated Show resolved Hide resolved
lib/swimmy/command/coop.rb Show resolved Hide resolved
lib/swimmy/service/coop.rb Outdated Show resolved Hide resolved
lib/swimmy/service/coop.rb Outdated Show resolved Hide resolved
lib/swimmy/service/coop.rb Outdated Show resolved Hide resolved
@miyake13000 miyake13000 merged commit 4a836ea into nomlab:master May 22, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants