{"id":19378284,"url":"https://github.com/kurehajime/classifile","last_synced_at":"2025-02-24T16:19:05.568Z","repository":{"id":56843534,"uuid":"403272592","full_name":"kurehajime/classifile","owner":"kurehajime","description":"Classifile is a tool for classifying files by Ruby DSL.","archived":false,"fork":false,"pushed_at":"2021-09-16T09:21:23.000Z","size":126,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-07T05:30:45.065Z","etag":null,"topics":["command-line-tool","dsl","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kurehajime.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-05T09:59:09.000Z","updated_at":"2021-09-16T09:20:59.000Z","dependencies_parsed_at":"2022-09-07T11:40:58.243Z","dependency_job_id":null,"html_url":"https://github.com/kurehajime/classifile","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kurehajime%2Fclassifile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kurehajime%2Fclassifile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kurehajime%2Fclassifile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kurehajime%2Fclassifile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kurehajime","download_url":"https://codeload.github.com/kurehajime/classifile/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240511296,"owners_count":19813237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line-tool","dsl","ruby"],"created_at":"2024-11-10T09:05:29.922Z","updated_at":"2025-02-24T16:19:05.545Z","avatar_url":"https://github.com/kurehajime.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Classifile\n\n[![status](https://github.com/kurehajime/classifile/actions/workflows/main_test.yml/badge.svg?branch=main)](https://github.com/kurehajime/classifile/actions/workflows/main_test.yml)\n\nClassifile is a tool for classifying files by Ruby DSL.\n\n## Installation\nRuby 3.0.0 or higher is required.\n\n    $ gem install classifile\n\n## Usage\n\n\n1. Write a DSL.\n\n    ```ruby\n   # dsl.rb \n   \n    dir \"Images\" do\n      image?\n      dir \"Dogs\" do\n        include? \"dog\"\n      end\n    \n      dir \"Cats\" do\n        dir \"Kittens\" do\n          include? \"kitten\"\n        end\n        include? \"cat\"\n      end\n    end\n    \n    dir \"Movies\" do\n      movie?\n    end\n    ```\n\n2. Prepare the files.\n\n```shell\ntemp/\n├from/\n│ ├─wild_dog.jpg\n│ ├─beautiful_cat.png\n│ ├─cute_kitten.gif\n│ └─dancing_cat.mpg\n└to/\n```\n\n3. Run the command\n\n```shell\n$ classifile --dsl dsl.rb --from \"/temp/from/*\"  --to \"/temp/to\" \n```\n\n4. Done!\n\n```shell\ntemp/\n├from/\n└to/\n　├Images/\n　│　├Dogs/\n　│　│　└─wild_dog.jpg\n　│　└Cats/\n　│　　│└─beautiful_cat.png\n　│　　└Kittens/\n　│　　　└─cute_kitten.gif\n　└Movies/\n　　└─dancing_cat.mpg\n```\n\n## Options\n\nCommand line options are here.\n\n|  Sort option  |  Long option  | Description  |\n| ---- | ---- |---- |\n|  -d  *PATH* |  --dsl *PATH*  |DSL path  |\n|  -f *PATH* |  --from *PATH*  |Source directory path  |\n|  -t *PATH* |  --to *PATH*  |Output directory path  |\n|  -p  |  --preview  |Preview Mode(don't move,don't copy)  |\n|  -c  |  --copy  |Copy Mode(don't move)  |\n|  -h  |  --help  |Show this help  |\n\n## Syntax\n\n### Classifile rules.\n\n1. The hierarchy of the dir block represents the directory hierarchy.\n2. If the check fails, exit the block.\n3. When It complete a block to the end, it will be saved in that directory.\n\n### Block methods\n\n#### dir block\n\n`dir` block represents a directory.\nA dir block can also be nested.\n\n```ruby\ndir \"Images\" do\n   image?\n   dir \"Dogs\" do\n      include? \"dog\"\n   end\nend\n```\n\n`dog.png -\u003e /Images/Dogs/dog.png`\n\n#### group block\n\n`group` block is a group that does not have a directory.\n\n```ruby\ngroup \"Animals\" do\n   dir \"Dogs\" do\n      include? \"dog\"\n   end\nend\n```\n\n`dog.png -\u003e /Dogs/dog.png`\n\n#### del block\n\n`del` block deletes the file.\n\n```ruby\ndel do\n   end_with? \".tmp\"\nend\n```\n\n`temp.tmp  will be deleted.`\n\n### Check methods\n\nThe check method checks if the file should be stored in that directory.\nIf it does not pass the check, it will leave the block immediately.\n\n#### include?\n\n`include?` method checks if the file name contains one of the strings.\n\n```ruby\ndir \"Dogs\" do\n   include? \"dog\"\nend\n\ndir \"Cats\" do\n   include? \"cat\" , \"kitten\"\nend\n```\n\n`dog.png -\u003e /Dogs/dog.png`\n`cat.png -\u003e /Cats/cat.png`\n`kitten.png -\u003e /Cats/kitten.png`\n\n\n#### end_with?\n\n`end_with?` method checks if the file name ends with one of the string.\n\n```ruby\ndir \"Archives\" do\n   end_with? \".zip\" , \".gz\"\nend\n```\n\n`doc.zip -\u003e /Archives/doc.zip`\n\n#### image? / sound? / movie?\n\n`image?` method checks if a file is an image or not.\n\n`sound?` method checks if a file is an sound or not.\n\n`movie?` method checks if a file is an movie or not.\n\n```ruby\ndir \"Images\" do\n   image?\nend\n\ndir \"Movies\" do\n   image?\nend\n```\n\n`cat.png -\u003e /Images/cat.png`\n`dog.avi -\u003e /Movies/dog.avi`\n\n\n#### assert / assert_nil / assert_includes ...\n\nYou can also use the [minitest](https://docs.ruby-lang.org/ja/2.1.0/class/MiniTest=3a=3aAssertions.html)\nmethods.\n\n```ruby\ndir \"Archives\" do |file|\n   assert_includes %w[.zip .gz], file.extname\nend\n```\n\n`doc.zip -\u003e /Archives/doc.zip`\n\n\n### Other methods\n\n#### empty_dir!\n\nIf `empty_dir!` is executed, the file will not be saved directly under that directory.\n\nIn this example, `dog.png` will be saved in `Images/Dogs`. In this example, `dog.png` will be saved in `Images/Dogs`, but `cat.png` will not be saved anywhere.\n\n```ruby\ndir \"Images\" do\n   empty_dir!\n   image?\n   dir \"Dogs\" do\n      include? \"dog\"\n   end\nend\n```\n\n`doc.png -\u003e /Images/Dogs/dog.png`\n`cat.png -\u003e  (not saved) `\n\n#### after_save\n\nExecute the method after the save is complete.\n\n```ruby\ndir \"Markdown\" do |_file|\n  end_with? \".md\"\n  after_save :hello\n  \n  def hello\n    puts \"hello\"\n  end\nend\n```\n\n`hello.md -\u003e /Markdown/hello.md`\n\nand \n\nThe output is \"hello\".\n\n\n### Block argument\n\nFile information can be obtained by block argument.\n\n```ruby\ndir \"Archives\" do |file|\n   assert_includes %w[.zip .gz], file.extname\nend\n```\n\n|  Property  |  Description  |\n| ---- | ---- |\n|  dirname  |  The directory before the move  |\n|  basename  |  File name  |\n|  pure_basename  |  File name without extension  |\n|  extname  |  Extension  |\n|  atime  |  Date and time of made  |\n|  ctime  |  Date and time of change  |\n|  size  |  File size  |\n|  to_path  |  Paths that will be saved  |\n\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/kurehajime/classifile. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/classifile/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Classifile project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/classifile/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkurehajime%2Fclassifile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkurehajime%2Fclassifile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkurehajime%2Fclassifile/lists"}