diff --git a/part01/.editorconfig b/part01/.editorconfig new file mode 100644 index 0000000..8f0c87a --- /dev/null +++ b/part01/.editorconfig @@ -0,0 +1,7 @@ +[*.cr] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true diff --git a/part01/.gitignore b/part01/.gitignore new file mode 100644 index 0000000..dabb3a1 --- /dev/null +++ b/part01/.gitignore @@ -0,0 +1,5 @@ +/doc/ +/lib/ +/bin/ +/.shards/ +!/.vscode/ \ No newline at end of file diff --git a/part01/.travis.yml b/part01/.travis.yml new file mode 100644 index 0000000..ffc7b6a --- /dev/null +++ b/part01/.travis.yml @@ -0,0 +1 @@ +language: crystal diff --git a/part01/.vscode/tasks.json b/part01/.vscode/tasks.json new file mode 100644 index 0000000..b46f9a3 --- /dev/null +++ b/part01/.vscode/tasks.json @@ -0,0 +1,30 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "taskName": "Crystal spec all", + "type": "shell", + "command": "sh -c 'cd ${workspaceRoot} && crystal spec'", + "group": { + "kind": "test", + "isDefault": true + }, + "presentation": { + "reveal": "always", + "panel": "new" + } + }, + { + "taskName": "Crystal spec current", + "type": "shell", + "command": "sh -c 'cd ${workspaceRoot} && crystal spec ${relativeFile}:${lineNumber}'", + "group": "test", + "presentation": { + "reveal": "always", + "panel": "new" + } + } + ] +} \ No newline at end of file diff --git a/part01/LICENSE b/part01/LICENSE new file mode 100644 index 0000000..b163f5d --- /dev/null +++ b/part01/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 at-grandpa + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/part01/README.md b/part01/README.md new file mode 100644 index 0000000..72fcbf6 --- /dev/null +++ b/part01/README.md @@ -0,0 +1 @@ +# 第01章 仮実装 \ No newline at end of file diff --git a/part01/shard.yml b/part01/shard.yml new file mode 100644 index 0000000..8b17150 --- /dev/null +++ b/part01/shard.yml @@ -0,0 +1,13 @@ +name: part01 +version: 0.1.0 + +authors: + - at-grandpa + +targets: + part01: + main: src/money.cr + +crystal: 0.23.1 + +license: MIT diff --git a/part01/spec/money_spec.cr b/part01/spec/money_spec.cr new file mode 100644 index 0000000..13bae56 --- /dev/null +++ b/part01/spec/money_spec.cr @@ -0,0 +1,11 @@ +require "./spec_helper" + +describe Money do + describe "multiplication" do + it "$5 * 2 = 10 になること" do + five = Money::Dollar.new(5) + five.times(2) + five.amount.should eq 10 + end + end +end diff --git a/part01/spec/spec_helper.cr b/part01/spec/spec_helper.cr new file mode 100644 index 0000000..a9a3f1b --- /dev/null +++ b/part01/spec/spec_helper.cr @@ -0,0 +1,2 @@ +require "spec" +require "../src/money" diff --git a/part01/src/money.cr b/part01/src/money.cr new file mode 100644 index 0000000..0f22eed --- /dev/null +++ b/part01/src/money.cr @@ -0,0 +1,4 @@ +require "./money/*" + +module Money +end diff --git a/part01/src/money/dollar.cr b/part01/src/money/dollar.cr new file mode 100644 index 0000000..1f5b95a --- /dev/null +++ b/part01/src/money/dollar.cr @@ -0,0 +1,12 @@ +module Money + class Dollar + property amount : Int32 + + def initialize(@amount : Int32) + end + + def times(multiplier : Int32) + @amount *= multiplier + end + end +end